예제 #1
0
  private void prepareRemote(View remoteView, int listNumber) {

    // Check if the remote we want is available
    if (remotesList.size() < listNumber + 1) return;

    DatabaseHelper helper = new DatabaseHelper(remoteView.getContext());
    try {
      helper.open();

      // Now get the current remote from the DB
      Cursor currentRemote = helper.getRemote(remotesList.get(listNumber));
      currentRemote.moveToFirst();

      final String remoteName =
          currentRemote.getString(currentRemote.getColumnIndex(DatabaseHelper.DB_COLUMN_NAME));

      Iterator remoteIterator = DatabaseHelper.UI_TO_DB_MAP.keySet().iterator();
      while (remoteIterator.hasNext()) {
        final String dbName = (String) remoteIterator.next();
        final int currentId = (DatabaseHelper.UI_TO_DB_MAP.get(dbName)).intValue();

        View currentButton = remoteView.findViewById(currentId);
        int currentButtonIndex = currentRemote.getColumnIndex(dbName);
        if (currentButtonIndex < 0) continue;

        String currentButtonName = currentRemote.getString(currentButtonIndex);
        if (currentButton != null) {
          currentButton.setVisibility(
              currentButtonName.compareTo("none") == 0 ? View.INVISIBLE : View.VISIBLE);
          currentButton.setOnClickListener(
              new Button.OnClickListener() {

                @Override
                public void onClick(View v) {
                  IrHelper.getInstance().sendKeyNative(remoteName, dbName);
                }
              });
        }
      }

      currentRemote.close();
      helper.close();
    } catch (SQLException e) {
      e.printStackTrace();
    }
  }
예제 #2
0
  @Override
  public void createAndAttachView(int id, FrameLayout frame) {
    // create a new layout from body.xml
    LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
    final View remoteView = inflater.inflate(R.layout.standout_activity_remote, frame, true);

    // Try to add the entries from the remote database to the spinner
    Spinner spinner = (Spinner) remoteView.findViewById(R.id.remote_list_spinner);
    DatabaseHelper dbHelper = new DatabaseHelper(getApplicationContext());
    try {
      // Get all the remotes from the Database
      dbHelper.open();
      Cursor cur = dbHelper.getAllRemotes();
      if (cur.getCount() != 0) {
        while (cur.moveToNext()) {
          // Get the names
          remotesList.add(cur.getString(cur.getColumnIndex("_name")));
        }
        cur.close();
      }
      dbHelper.close();
    } catch (SQLException e) {
      e.printStackTrace();
    }

    // What to do once a spinner item was selected
    spinner.setOnItemSelectedListener(
        new Spinner.OnItemSelectedListener() {
          @Override
          public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            prepareRemote(remoteView, position);
          }

          @Override
          public void onNothingSelected(AdapterView<?> parent) {
            // Nothing done here ATM
          }
        });

    // If the list is empty, open the configuration
    // otherwise continue populating
    if (remotesList.size() == 0) {
      // Close the remotes
      closeAll();

      // Open Configuration
      Intent dialogIntent = new Intent(getBaseContext(), ConfigurationActivity.class);
      dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      getApplication().startActivity(dialogIntent);
    } else {
      // Add the Add device note and set the adapter for the spinner
      // remotesList.add(getResources().getString(R.string.add_device_prompt));
      ArrayAdapter<String> dataAdapter =
          new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, remotesList);
      dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
      spinner.setAdapter(dataAdapter);

      // Let the close button close the remote
      Button closeButton = (Button) remoteView.findViewById(R.id.button_close);
      closeButton.setOnClickListener(
          new Button.OnClickListener() {
            public void onClick(View v) {
              // Close the Remote
              IrHelper.getInstance().stopIrNative();
              closeAll();
            }
          });
    }
  }