Example #1
0
    @Override
    public void onIncomingReceipt(ChatSession ses, String id) {
      Imps.updateConfirmInDb(mContentResolver, mContactId, id, true);

      synchronized (mRemoteListeners) {
        int N = mRemoteListeners.beginBroadcast();
        for (int i = 0; i < N; i++) {
          IChatListener listener = mRemoteListeners.getBroadcastItem(i);
          try {
            listener.onIncomingReceipt(ChatSessionAdapter.this, id);
          } catch (RemoteException e) {
            // The RemoteCallbackList will take care of removing the
            // dead listeners.
          }
        }
        mRemoteListeners.finishBroadcast();
      }
    }
Example #2
0
    @Override
    public void onTransferComplete(
        boolean outgoing,
        String offerId,
        String from,
        String url,
        String mimeType,
        String filePath) {

      try {

        if (outgoing) {
          Imps.updateConfirmInDb(service.getContentResolver(), mContactId, offerId, true);
        } else {

          try {
            boolean isVerified = getDefaultOtrChatSession().isKeyVerified(from);

            int type =
                isVerified
                    ? Imps.MessageType.INCOMING_ENCRYPTED_VERIFIED
                    : Imps.MessageType.INCOMING_ENCRYPTED;

            insertOrUpdateChat(filePath);

            Uri messageUri =
                Imps.insertMessageInDb(
                    service.getContentResolver(),
                    mIsGroupChat,
                    getId(),
                    true,
                    from,
                    filePath,
                    System.currentTimeMillis(),
                    type,
                    0,
                    offerId,
                    mimeType);

            int percent = (int) (100);

            String[] path = url.split("/");
            String sanitizedPath = SystemServices.sanitize(path[path.length - 1]);

            final int N = mRemoteListeners.beginBroadcast();
            for (int i = 0; i < N; i++) {
              IChatListener listener = mRemoteListeners.getBroadcastItem(i);
              try {
                listener.onIncomingFileTransferProgress(sanitizedPath, percent);
              } catch (RemoteException e) {
                // The RemoteCallbackList will take care of removing the
                // dead listeners.
              }
            }
            mRemoteListeners.finishBroadcast();

            if (N == 0) {
              String nickname = getNickName(from);

              mStatusBarNotifier.notifyChat(
                  mConnection.getProviderId(),
                  mConnection.getAccountId(),
                  getId(),
                  from,
                  nickname,
                  service.getString(R.string.file_notify_text, mimeType, nickname),
                  false);
            }
          } catch (Exception e) {
            Log.e(ImApp.LOG_TAG, "Error updating file transfer progress", e);
          }
        }

        /**
         * if (mimeType != null && mimeType.startsWith("audio")) { MediaPlayer mp = new
         * MediaPlayer(); try { mp.setDataSource(file.getCanonicalPath());
         *
         * <p>mp.prepare(); mp.start();
         *
         * <p>} catch (IOException e) { // TODO Auto-generated catch block //e.printStackTrace(); }
         * }
         */
      } catch (Exception e) {
        //   mHandler.showAlert(service.getString(R.string.error_chat_file_transfer_title),
        // service.getString(R.string.error_chat_file_transfer_body));
        OtrDebugLogger.log("error reading file", e);
      }
    }