Ejemplo n.º 1
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.key_server_query_layout);

    mQuery = (EditText) findViewById(R.id.query);
    mSearch = (Button) findViewById(R.id.btn_search);
    mList = (ListView) findViewById(R.id.list);
    mAdapter = new KeyInfoListAdapter(this);
    mList.setAdapter(mAdapter);

    mKeyServer = (Spinner) findViewById(R.id.keyServer);
    ArrayAdapter<String> adapter =
        new ArrayAdapter<String>(
            this, android.R.layout.simple_spinner_item, mPreferences.getKeyServers());
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mKeyServer.setAdapter(adapter);
    if (adapter.getCount() > 0) {
      mKeyServer.setSelection(0);
    } else {
      mSearch.setEnabled(false);
    }

    mList.setOnItemClickListener(
        new OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> adapter, View view, int position, long keyId) {
            get(keyId);
          }
        });

    mSearch.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            String query = mQuery.getText().toString();
            search(query);
          }
        });

    Intent intent = getIntent();
    if (Apg.Intent.LOOK_UP_KEY_ID.equals(intent.getAction())
        || Apg.Intent.LOOK_UP_KEY_ID_AND_RETURN.equals(intent.getAction())) {
      long keyId = intent.getLongExtra(Apg.EXTRA_KEY_ID, 0);
      if (keyId != 0) {
        String query = "0x" + Apg.keyToHex(keyId);
        mQuery.setText(query);
        search(query);
      }
    }
  }
Ejemplo n.º 2
0
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
      KeyInfo keyInfo = mKeys.get(position);

      View view = mInflater.inflate(R.layout.key_server_query_result_item, null);

      TextView mainUserId = (TextView) view.findViewById(R.id.mainUserId);
      mainUserId.setText(R.string.unknownUserId);
      TextView mainUserIdRest = (TextView) view.findViewById(R.id.mainUserIdRest);
      mainUserIdRest.setText("");
      TextView keyId = (TextView) view.findViewById(R.id.keyId);
      keyId.setText(R.string.noKey);
      TextView algorithm = (TextView) view.findViewById(R.id.algorithm);
      algorithm.setText("");
      TextView status = (TextView) view.findViewById(R.id.status);
      status.setText("");

      String userId = keyInfo.userIds.get(0);
      if (userId != null) {
        String chunks[] = userId.split(" <", 2);
        userId = chunks[0];
        if (chunks.length > 1) {
          mainUserIdRest.setText("<" + chunks[1]);
        }
        mainUserId.setText(userId);
      }

      keyId.setText(Apg.getSmallFingerPrint(keyInfo.keyId));

      if (mainUserIdRest.getText().length() == 0) {
        mainUserIdRest.setVisibility(View.GONE);
      }

      algorithm.setText("" + keyInfo.size + "/" + keyInfo.algorithm);

      if (keyInfo.revoked != null) {
        status.setText("revoked");
      } else {
        status.setVisibility(View.GONE);
      }

      LinearLayout ll = (LinearLayout) view.findViewById(R.id.list);
      if (keyInfo.userIds.size() == 1) {
        ll.setVisibility(View.GONE);
      } else {
        boolean first = true;
        boolean second = true;
        for (String uid : keyInfo.userIds) {
          if (first) {
            first = false;
            continue;
          }
          if (!second) {
            View sep = new View(mActivity);
            sep.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, 1));
            sep.setBackgroundResource(android.R.drawable.divider_horizontal_dark);
            ll.addView(sep);
          }
          TextView uidView =
              (TextView) mInflater.inflate(R.layout.key_server_query_result_user_id, null);
          uidView.setText(uid);
          ll.addView(uidView);
          second = false;
        }
      }

      return view;
    }