// PENDING // GET LIST OF AVAILABLE PEERS connected to same Wifi network @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if (!ServiceHelpers.isPeerListEmpty()) { ArrayList<HashMap> peers = ServiceHelpers.getPeersList(); String name = parent.getItemAtPosition(position).toString(); String ipAddress = (String) peers.get(position).get("ip"); String userTable = (String) peers.get(position).get("user_table"); // showActionsDialog(name, ipAddress, userTable); // Intent intent = new Intent (getApplicationContext(), ChatActivity.class); Intent intent = new Intent(MainActivity.this, ChatActivity.class); // this is used to bring the chat activity to foreground // intent.addFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT); boolean username = true; intent.putExtra("CONTACT_NAME", username); intent.putExtra("IP_ADDRESS", ipAddress); intent.putExtra("user_table", userTable); startActivity(intent); } }
@Override protected void onResume() { super.onResume(); if (!AppGlobals.isVirgin() && AppGlobals.isServiceOn() && !ServiceHelpers.DISCOVER && LongRunningService.isRunning()) { ServiceHelpers.discover(MainActivity.this, peerList); } }
// custom button // button with two states // if button is checked, starts a service.. // this is used to list available devices when button is clicked. ie; displays username @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { switch (buttonView.getId()) { case R.id.switch_service: if (isChecked) { startService(new Intent(getApplicationContext(), LongRunningService.class)); layoutMainTwo.setVisibility(View.VISIBLE); AppGlobals.setService(true); showUsername.setTextColor(Color.parseColor("#4CAF50")); ServiceHelpers.discover(MainActivity.this, peerList); } else { stopService(new Intent(getApplicationContext(), LongRunningService.class)); layoutMainTwo.setVisibility(View.GONE); AppGlobals.setService(false); showUsername.setTextColor(Color.parseColor("#F44336")); ServiceHelpers.stopDiscover(); } invalidateOptionsMenu(); } }
@Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == R.id.tv_contact_name_call) { Intent intent = new Intent(MainActivity.this, CallActivity.class); String username = String.valueOf(true); intent.putExtra("CONTACT_NAME", username); intent.putExtra("CALL_STATE", "OUTGOING"); String ipAddress = String.valueOf(true); intent.putExtra("IP_ADDRESS", ipAddress); startActivity(intent); MessagingHelpers.sendCallRequest(username, ipAddress, ServiceHelpers.BROADCAST_PORT); } // when settings is clicked, the user gets visible on mainlayout if (id == R.id.action_settings) { layoutMain.setVisibility(View.VISIBLE); layoutUsername.setVisibility(View.GONE); AppGlobals.setVirgin(false); showUsername.setText("Username: "******"#4CAF50")); } else { // red = offline layoutMainTwo.setVisibility(View.GONE); showUsername.setTextColor(Color.parseColor("#F44336")); } // when refresh is clicked, it shows a list of peers in the same network } if (id == R.id.action_refresh) { peerList.setAdapter(null); if (!ServiceHelpers.DISCOVER) { ServiceHelpers.discover(MainActivity.this, peerList); } return true; } return super.onOptionsItemSelected(item); }
// called when we override or create an own activity @Override protected void onPause() { super.onPause(); ServiceHelpers.stopDiscover(); }