コード例 #1
0
  private void sendMedia(final String mediaType, String filePath) {
    File f = new File(filePath);
    final String key = S3UploadService.generateKey(f);
    S3UploadService.uploadFile(
        key,
        f,
        new TransferListener() {
          public void onStateChanged(int id, TransferState state) {
            switch (state) {
              case COMPLETED:
                updateList(mediaType, S3UploadService.buildUrl(key), false);
                HashMap<String, String> content = new HashMap<>();
                content.put("type", mediaType);
                content.put("url", S3UploadService.buildUrl(key));
                send(content);
                break;
              case CANCELED:
              case FAILED:
                Toast.makeText(ChatActivity.this, "Unable to upload.", Toast.LENGTH_LONG).show();
                break;
            }
          }

          public void onProgressChanged(int id, long bytesCurrent, long bytesTotal) {}

          public void onError(int id, Exception ex) {
            Log.e(TAG, "send(): exception during upload", ex);
          }
        });
  }
コード例 #2
0
 /**
  * On destroying of this activity, unregister this activity as a listener so it won't process any
  * incoming messages.
  */
 @Override
 public void onDestroy() {
   MMX.unregisterListener(mEventListener);
   S3UploadService.destroy();
   mGPS.stopUsingGPS();
   super.onDestroy();
 }
コード例 #3
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_chat);

    if (MMX.getCurrentUser() == null) {
      MMX.unregisterListener(mEventListener);
      MMX.logout(null);
      Intent intent = new Intent(ChatActivity.this, LoginActivity.class);
      startActivity(intent);
    }

    mUser = getIntent().getParcelableExtra("User");

    MMX.registerListener(mEventListener);
    S3UploadService.init(this);
    mGPS = new GPSTracker(this);

    ActionBar ab = getActionBar();
    if (ab != null) {
      ab.setTitle("Chatting With: " + mUser.getUsername());
    }

    rvMessages = (RecyclerView) findViewById(R.id.rvMessages);
    etMessage = (EditText) findViewById(R.id.etMessage);
    btnSendText = (ImageButton) findViewById(R.id.btnSendText);
    btnSendPicture = (ImageButton) findViewById(R.id.btnSendPicture);
    btnSendLocation = (ImageButton) findViewById(R.id.btnSendLocation);
    btnSendVideo = (ImageButton) findViewById(R.id.btnSendVideo);

    messageList = new ArrayList<>();
    adapter = new MessageRecyclerViewAdapter(this, messageList);

    rvMessages.setAdapter(new SlideInBottomAnimationAdapter(adapter));
    final LinearLayoutManager layoutManager = new LinearLayoutManager(this);
    layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    layoutManager.setStackFromEnd(true);
    layoutManager.setReverseLayout(false);
    rvMessages.setLayoutManager(layoutManager);

    etMessage.setOnKeyListener(
        new View.OnKeyListener() {
          public boolean onKey(View v, int keyCode, KeyEvent event) {
            if ((event.getAction() == KeyEvent.ACTION_DOWN)
                && (keyCode == KeyEvent.KEYCODE_ENTER)) {
              sendMessage();
              return true;
            }
            return false;
          }
        });

    btnSendText.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            sendMessage();
          }
        });

    btnSendPicture.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            selectImage();
          }
        });

    btnSendLocation.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            sendLocation();
          }
        });

    btnSendVideo.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            selectVideo();
          }
        });
  }