Пример #1
0
  private void updateComputer(ComputerDetails details) {
    ComputerObject existingEntry = null;

    for (int i = 0; i < pcGridAdapter.getCount(); i++) {
      ComputerObject computer = (ComputerObject) pcGridAdapter.getItem(i);

      // Check if this is the same computer
      if (details.uuid.equals(computer.details.uuid)) {
        existingEntry = computer;
        break;
      }
    }

    if (existingEntry != null) {
      // Replace the information in the existing entry
      existingEntry.details = details;
    } else {
      // Add a new entry
      pcGridAdapter.addComputer(new ComputerObject(details));

      // Remove the "Discovery in progress" view
      noPcFoundLayout.setVisibility(View.INVISIBLE);
    }

    // Notify the view that the data has changed
    pcGridAdapter.notifyDataSetChanged();
  }
Пример #2
0
  @Override
  public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    stopComputerUpdates(false);

    // Call superclass
    super.onCreateContextMenu(menu, v, menuInfo);

    AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
    ComputerObject computer = (ComputerObject) pcGridAdapter.getItem(info.position);

    // Inflate the context menu
    if (computer.details.reachability == ComputerDetails.Reachability.OFFLINE
        || computer.details.reachability == ComputerDetails.Reachability.UNKNOWN) {
      menu.add(Menu.NONE, WOL_ID, 1, getResources().getString(R.string.pcview_menu_send_wol));
      menu.add(Menu.NONE, DELETE_ID, 2, getResources().getString(R.string.pcview_menu_delete_pc));
    } else if (computer.details.pairState != PairState.PAIRED) {
      menu.add(Menu.NONE, PAIR_ID, 1, getResources().getString(R.string.pcview_menu_pair_pc));
      menu.add(Menu.NONE, DELETE_ID, 2, getResources().getString(R.string.pcview_menu_delete_pc));
    } else {
      if (computer.details.runningGameId != 0) {
        menu.add(Menu.NONE, RESUME_ID, 1, getResources().getString(R.string.applist_menu_resume));
        menu.add(Menu.NONE, QUIT_ID, 2, getResources().getString(R.string.applist_menu_quit));
      }

      menu.add(Menu.NONE, APP_LIST_ID, 3, getResources().getString(R.string.pcview_menu_app_list));

      // FIXME: We used to be able to unpair here but it's been broken since GFE 2.1.x, so I've
      // replaced
      // it with delete which actually work
      menu.add(Menu.NONE, DELETE_ID, 4, getResources().getString(R.string.pcview_menu_delete_pc));
    }
  }
Пример #3
0
  private void removeComputer(ComputerDetails details) {
    for (int i = 0; i < pcGridAdapter.getCount(); i++) {
      ComputerObject computer = (ComputerObject) pcGridAdapter.getItem(i);

      if (details.equals(computer.details)) {
        pcGridAdapter.removeComputer(computer);
        pcGridAdapter.notifyDataSetChanged();

        if (pcGridAdapter.getCount() == 0) {
          // Show the "Discovery in progress" view
          noPcFoundLayout.setVisibility(View.VISIBLE);
        }

        break;
      }
    }
  }
Пример #4
0
  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();
  }
Пример #5
0
  @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);
    }
  }