コード例 #1
0
ファイル: ChatActivity.java プロジェクト: ciriux2/android-rsa
  @Override
  public void onCreate(Bundle savedInstanceState) {
    context = getApplicationContext();
    this.connection = Conexion.getInstance();
    this.roster = RosterManager.getRosterInstance();
    chatMan = ContactsActivity.chatMan;
    chat = chatMan.chat;
    super.onCreate(savedInstanceState);
    setContentView(R.layout.chat);
    destJid = getIntent().getStringExtra("destJid");
    myJid = this.connection.getUser();
    cipher = RosterManager.isSecure(destJid);
    Bundle bundle = getIntent().getExtras();
    passPhrase = bundle.getString(AndroidRsaConstants.PASSPHRASE);

    String parsedDest = StringUtils.parseBareAddress(destJid);
    Log.d(TAG, "Creado chat con " + roster.getEntry(parsedDest).getName() + " cifrado=" + cipher);

    if (chat == null) {
      chatMan.createChat(destJid, messageListener);
      chat = chatMan.getChat();
      if (cipher) {
        Message m = new Message(destJid);
        try {
          chat.sendMessage(m);
        } catch (XMPPException e) {
          e.printStackTrace();
        }
      }
    } else {
      chat.addMessageListener(messageListener);
    }

    adapter = new ChatAdapter(this, listMessages);
    setListAdapter(adapter);
    myListView = getListView();
    myListView.setDivider(null);

    if (cipher) {
      Bitmap bm = AvatarsCache.getAvatar(destJid);
      try {
        cert = Decode.decode(bm);
      } catch (IOException e) {
        e.printStackTrace();
      } catch (CertificateException e) {
        e.printStackTrace();
      }
    }
  }
コード例 #2
0
ファイル: ChatActivity.java プロジェクト: ciriux2/android-rsa
  public void send(View view) {
    Message message = new Message(destJid);
    EditText editText = (EditText) findViewById(R.id.textInput);
    String plainText = editText.getText().toString();
    editText.setText("");

    message.setFrom(myJid);
    message.setTo(destJid);

    Message m = new Message();
    m.setFrom(myJid);
    m.setBody(plainText);
    SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
    m.setSubject(sdf.format(new Date()));
    listMessages.add(m);
    refreshAdapter();
    myListView.smoothScrollToPosition(adapter.getCount() - 1);

    if (!cipher) {
      try {
        message.setBody(plainText);
        chatMan.getChat().sendMessage(message);
        Log.d(TAG, "Enviando: " + message.getBody());

      } catch (XMPPException e) {
        Log.d(TAG, "ERROR al enviar mensaje");
      }
    } else {
      try {
        String encodedMessage = RSA.cipher(plainText, cert.getPublicKey());
        message.setBody(encodedMessage);
        chatMan.getChat().sendMessage(message);
        Log.d(TAG, "Enviando cifrado: " + message.getBody() + " " + plainText);

      } catch (Exception e) {
        Log.d(TAG, "PETO ENVIANDO CIFRADOOOO");
        e.printStackTrace();
      }
    }
  }
コード例 #3
0
ファイル: ChatActivity.java プロジェクト: ciriux2/android-rsa
 @Override
 public void onBackPressed() {
   chatMan.chat = null;
   chat = null;
   super.onBackPressed();
 }