Пример #1
0
 @Override
 public boolean onPrepareOptionsMenu(Menu menu) {
   MenuItem menuItemParticipants = menu.findItem(R.id.menu_participants);
   MenuItem menuItemSendFile = menu.findItem(R.id.menu_send_file);
   MenuItem menuItemLeave = menu.findItem(R.id.menu_close_session);
   try {
     if (mGroupChat != null) {
       menuItemParticipants.setEnabled(mGroupChat.isAllowedToInviteParticipants());
       menuItemLeave.setEnabled(mGroupChat.isAllowedToLeave());
       FileTransferService fileTransferService = getFileTransferApi();
       menuItemSendFile.setEnabled(
           fileTransferService.isAllowedToTransferFileToGroupChat(mChatId));
     } else {
       menuItemParticipants.setEnabled(false);
       menuItemSendFile.setEnabled(false);
       menuItemLeave.setEnabled(false);
     }
   } catch (RcsServiceException e) {
     showException(e);
   }
   return true;
 }
Пример #2
0
 @Override
 public void onDestroy() {
   if (LogUtils.isActive) {
     Log.d(LOGTAG, "onDestroy");
   }
   super.onDestroy();
   if (mFileTransferService != null && isServiceConnected(RcsServiceName.FILE_TRANSFER)) {
     // Remove file transfer listener
     try {
       mFileTransferService.removeEventListener(mFileTransferListener);
     } catch (RcsServiceException e) {
       Log.w(LOGTAG, ExceptionUtil.getFullStackTrace(e));
     }
   }
 }
Пример #3
0
  private void initiateTransfer(ContactId remote) {
    /* Get thumbnail option */
    CheckBox ftThumb = (CheckBox) findViewById(R.id.ft_thumb);
    boolean tryToSendFileicon = ftThumb.isChecked();
    String mimeType = getContentResolver().getType(mFile);
    if (tryToSendFileicon && mimeType != null && !mimeType.startsWith("image")) {
      tryToSendFileicon = false;
    }
    try {
      /* Only take persistable permission for content Uris */
      takePersistableContentUriPermission(this, mFile);
      /* Initiate transfer */
      mFileTransfer = mFileTransferService.transferFile(remote, mFile, tryToSendFileicon);
      mFileTransferId = mFileTransfer.getTransferId();
      mProgressDialog = showProgressDialog(getString(R.string.label_command_in_progress));
      mProgressDialog.setOnCancelListener(
          new OnCancelListener() {
            public void onCancel(DialogInterface dialog) {
              Toast.makeText(
                      InitiateFileTransfer.this,
                      getString(R.string.label_transfer_cancelled),
                      Toast.LENGTH_SHORT)
                  .show();
              quitSession();
            }
          });
      /* Disable UI */
      mSpinner.setEnabled(false);
      /* Hide buttons */
      mInviteBtn.setVisibility(View.INVISIBLE);
      mSelectBtn.setVisibility(View.INVISIBLE);
      ftThumb.setVisibility(View.INVISIBLE);

    } catch (RcsServiceException e) {
      showExceptionThenExit(e);
    }
  }
Пример #4
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    intitialize();
    ContactId remoteContact;
    Intent intent = getIntent();
    boolean resuming = FileTransferIntent.ACTION_RESUME.equals(intent.getAction());

    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    setContentView(R.layout.filetransfer_initiate);

    /* Set contact selector */
    mSpinner = (Spinner) findViewById(R.id.contact);

    /* Set buttons callback */
    mInviteBtn = (Button) findViewById(R.id.invite_btn);
    mInviteBtn.setOnClickListener(mBtnInviteListener);
    mInviteBtn.setEnabled(false);
    mSelectBtn = (Button) findViewById(R.id.select_btn);
    mSelectBtn.setOnClickListener(mBtnSelectListener);
    mSelectBtn.setEnabled(false);

    mPauseBtn = (Button) findViewById(R.id.pause_btn);
    mPauseBtn.setOnClickListener(mBtnPauseListener);
    mPauseBtn.setEnabled(false);

    mResumeBtn = (Button) findViewById(R.id.resume_btn);
    mResumeBtn.setOnClickListener(mBtnResumeListener);
    mResumeBtn.setEnabled(false);

    TableRow expiration = (TableRow) findViewById(R.id.expiration);
    expiration.setVisibility(View.GONE);

    if (!isServiceConnected(RcsServiceName.FILE_TRANSFER)) {
      showMessageThenExit(R.string.label_service_not_available);
      return;
    }
    startMonitorServices(RcsServiceName.FILE_TRANSFER);
    mFileTransferService = getFileTransferApi();
    try {
      mFileTransferService.addEventListener(mFileTransferListener);
      if (resuming) {
        /* Get resuming info */
        FileTransferDAO ftdao =
            (FileTransferDAO) (intent.getExtras().getSerializable(BUNDLE_FTDAO_ID));
        if (ftdao == null) {
          if (LogUtils.isActive) {
            Log.e(LOGTAG, "onCreate cannot read File Transfer resuming info");
          }
          finish();
          return;
        }
        remoteContact = ftdao.getContact();
        mFileTransferId = ftdao.getTransferId();
        mFilename = ftdao.getFilename();
        mFilesize = ftdao.getSize();
        ArrayAdapter<String> adapter =
            new ArrayAdapter<>(
                this,
                android.R.layout.simple_spinner_item,
                new String[] {remoteContact.toString()});
        mSpinner.setAdapter(adapter);
        TextView uriEdit = (TextView) findViewById(R.id.uri);
        TextView sizeEdit = (TextView) findViewById(R.id.size);
        sizeEdit.setText((mFilesize / 1024) + " KB");
        uriEdit.setText(mFilename);
        /* Check if session still exists */
        if (mFileTransferService.getFileTransfer(mFileTransferId) == null) {
          /* Session not found or expired */
          showMessageThenExit(R.string.label_transfer_session_has_expired);
          return;
        }
        if (LogUtils.isActive) {
          Log.d(
              LOGTAG,
              "onCreate (file="
                  + mFilename
                  + ") (size="
                  + mFilesize
                  + ") (contact="
                  + remoteContact
                  + ")");
        }
      } else {
        mSpinner.setAdapter(ContactListAdapter.createRcsContactListAdapter(this));
        /* Enable button if contact available */
        if (mSpinner.getAdapter().getCount() != 0) {
          mSelectBtn.setEnabled(true);
        }
        if (LogUtils.isActive) {
          Log.d(LOGTAG, "onCreate");
        }
      }

    } catch (RcsServiceException e) {
      showExceptionThenExit(e);
    }
  }