private void initializeViews() { setContentView(R.layout.activity_pc_view); UiHelper.notifyNewRootView(this); // Set default preferences if we've never been run PreferenceManager.setDefaultValues(this, R.xml.preferences, false); // Setup the list view ImageButton settingsButton = (ImageButton) findViewById(R.id.settingsButton); ImageButton addComputerButton = (ImageButton) findViewById(R.id.manuallyAddPc); settingsButton.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { startActivity(new Intent(PcView.this, StreamSettings.class)); } }); addComputerButton.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(PcView.this, AddComputerManually.class); startActivity(i); } }); getFragmentManager() .beginTransaction() .replace(R.id.pcFragmentContainer, new AdapterFragment()) .commitAllowingStateLoss(); noPcFoundLayout = (RelativeLayout) findViewById(R.id.no_pc_found_layout); if (pcGridAdapter.getCount() == 0) { noPcFoundLayout.setVisibility(View.VISIBLE); } else { noPcFoundLayout.setVisibility(View.INVISIBLE); } pcGridAdapter.notifyDataSetChanged(); }
@Override public boolean onContextItemSelected(MenuItem item) { AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); final ComputerObject computer = (ComputerObject) pcGridAdapter.getItem(info.position); switch (item.getItemId()) { case PAIR_ID: doPair(computer.details); return true; case UNPAIR_ID: doUnpair(computer.details); return true; case WOL_ID: doWakeOnLan(computer.details); return true; case DELETE_ID: if (managerBinder == null) { Toast.makeText( PcView.this, getResources().getString(R.string.error_manager_not_running), Toast.LENGTH_LONG) .show(); return true; } managerBinder.removeComputer(computer.details.name); removeComputer(computer.details); return true; case APP_LIST_ID: doAppList(computer.details); return true; case RESUME_ID: if (managerBinder == null) { Toast.makeText( PcView.this, getResources().getString(R.string.error_manager_not_running), Toast.LENGTH_LONG) .show(); return true; } ServerHelper.doStart( this, new NvApp("app", computer.details.runningGameId), computer.details, managerBinder); return true; case QUIT_ID: if (managerBinder == null) { Toast.makeText( PcView.this, getResources().getString(R.string.error_manager_not_running), Toast.LENGTH_LONG) .show(); return true; } // Display a confirmation dialog first UiHelper.displayQuitConfirmationDialog( this, new Runnable() { @Override public void run() { ServerHelper.doQuit( PcView.this, ServerHelper.getCurrentAddressFromComputer(computer.details), new NvApp("app", 0), managerBinder, null); } }, null); return true; default: return super.onContextItemSelected(item); } }