Exemple #1
0
  @Override
  protected void onResume() {
    super.onResume();
    if (!AppGlobals.isVirgin()
        && AppGlobals.isServiceOn()
        && !ServiceHelpers.DISCOVER
        && LongRunningService.isRunning()) {

      ServiceHelpers.discover(MainActivity.this, peerList);
    }
  }
Exemple #2
0
  @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);
  }
Exemple #3
0
 // 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();
   }
 }
Exemple #4
0
 // PENDING
 private void notVirgin() {
   layoutMain.setVisibility(View.VISIBLE);
   layoutUsername.setVisibility(View.GONE);
   AppGlobals.setVirgin(false);
   //  showUsername.setText("Username: "******"#4CAF50"));
   // } else {
   //     layoutMainTwo.setVisibility(View.GONE);
   //     showUsername.setTextColor(Color.parseColor("#F44336"));
   //  }
 }
Exemple #5
0
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_main, menu);

    if (AppGlobals.isServiceOn()) {
      // when service is enabled, refresh and settings will get visible
      // for the user
      menu.findItem(R.id.action_refresh).setVisible(true);
      menu.findItem(R.id.action_settings).setVisible(true);

    } else {
      menu.findItem(R.id.action_refresh).setVisible(false);
      menu.findItem(R.id.action_settings).setVisible(false);
    }
    return true;
  }
Exemple #6
0
  // called when activity first starts up
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    // on create is called,extends parent class
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    sInstance = this;

    startActivity(new Intent(this, MessagesListActivity.class));
    layoutUsername = (LinearLayout) findViewById(R.id.layout_username);
    layoutMain = (RelativeLayout) findViewById(R.id.layout_main);
    layoutMainTwo = (LinearLayout) findViewById(R.id.layout_main_two);
    // check here
    showUsername = (TextView) findViewById(R.id.tv_username);
    serviceSwitch = (Switch) findViewById(R.id.switch_service);
    serviceSwitch.setOnCheckedChangeListener(this);
    peerList = (ListView) findViewById(R.id.lv_peer_list);
    peerList.setOnItemClickListener(this);

    //  if appglobals is virgin, hides mainlayout, sets username visible,captures username
    // else notvirgin
    if (AppGlobals.isVirgin()) {
      // hides main layout
      layoutMain.setVisibility(View.GONE);
      // username is set as visible in second interface
      layoutUsername.setVisibility(View.VISIBLE);
      // checks xml file to get username and display it
      editTextUsername = (EditText) findViewById(R.id.editTextDisplayName);
      // sets listener from edittextdisplayname
      editTextUsername.setOnFocusChangeListener(this);
      // xml button, capture button from layout
      Button startButton = (Button) findViewById(R.id.buttonStart);
      // listener is set , when button is clicked, operation starts
      startButton.setOnClickListener(this);
    } else {
      notVirgin();
    }

    // REMOVE
    //        Toolbar mToolbar = (Toolbar) findViewById(R.id.my_toolbar);
    //  setSupportActionBar(mToolbar);

    getSupportActionBar().setTitle("VOIP");
    //  getSupportActionBar().setSubtitle("T");
  }
Exemple #7
0
 @Override
 // on click, it reads data from text box, if empty, shows invalid notification,
 // first interface, we get an edit text view to enter a username
 // next, the button is to be pressed
 // once the button is pressed, it inputs the username
 // if the username length is less than 1, invalid username notification appears
 public void onClick(View v) {
   switch (v.getId()) {
     case R.id.buttonStart:
       Log.i("wifiMessenger", "Start button pressed");
       String username = editTextUsername.getText().toString();
       if (username.trim().length() < 1) {
         Toast.makeText(getApplicationContext(), "Invalid Username", Toast.LENGTH_SHORT).show();
       } else {
         AppGlobals.putName(username);
         notVirgin();
       }
       break;
   }
 }