Exemplo n.º 1
0
  @Override
  public void onCreate() {
    super.onCreate();
    MMX.init(this, R.raw.whisper);
    SimpleFacebookConfiguration configuration =
        new SimpleFacebookConfiguration.Builder()
            .setAppId(getString(R.string.app_id))
            .setNamespace(Constants.APP_NS)
            .setPermissions(Constants.permissions)
            .build();
    SimpleFacebook.setConfiguration(configuration);
    Instance = this;
    applicationHandler = new Handler(getInstance().getMainLooper());
    NativeLoader.initNativeLibs(App.getInstance());
    MMX.registerWakeupBroadcast(new Intent("MY_WAKEUP_ACTION"));
    MMX.registerListener(
        new MMX.EventListener() {
          @Override
          public boolean onMessageReceived(MMXMessage mmxMessage) {
            // sendNotification(mmxMessage);
            return true;
          }

          @Override
          public boolean onLoginRequired(MMX.LoginReason reason) {
            if (reason == MMX.LoginReason.SERVICE_UNAVAILABLE) attemptLogin();
            else if (reason == MMX.LoginReason.DISCONNECTED) attemptLogin();
            else if (reason == MMX.LoginReason.SERVICE_AVAILABLE) {;
            } else if (reason == MMX.LoginReason.CREDENTIALS_EXPIRED) goToLoginActivity();
            return true;
          }
        });
  }
 /**
  * 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();
 }
Exemplo n.º 3
0
  private void attemptLogin() {
    SharedPreferences sharedPref =
        this.getSharedPreferences(getString(R.string.user_login_details), Context.MODE_PRIVATE);
    String username = sharedPref.getString(getString(R.string.username), "notfound");
    String password_string = sharedPref.getString(getString(R.string.password), "notfound");
    if (username.contains("notfound")) {
    } else {
      byte[] password =
          password_string
              .getBytes(); // since the password in pref file is string, conversion is necessary.
      MMX.login(
          username,
          password,
          new MMX.OnFinishedListener<Void>() {
            @Override
            public void onSuccess(Void aVoid) {
              MMX.start();
            }

            @Override
            public void onFailure(MMX.FailureCode failureCode, Throwable throwable) {
              if (failureCode == MMX.FailureCode.DEVICE_CONCURRENT_LOGIN) {;
              } else if (failureCode == MMX.FailureCode.SERVICE_UNAVAILABLE) attemptLogin();
              else if (failureCode == MMX.FailureCode.SERVER_AUTH_FAILED) {;
              } else if (failureCode == MMX.FailureCode.SERVER_ERROR) attemptLogin();
            }
          });
    }
  }
  @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();
          }
        });
  }