Example #1
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));
     }
   }
 }
Example #2
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);
    }
  }