Example #1
0
 /** 设置recyclerView */
 public void setRecyclerView() {
   recyclerView = (RecyclerView) findViewById(R.id.con_recycler);
   recyclerView.setHasFixedSize(true);
   mLayoutManager = new LinearLayoutManager(this);
   mLayoutManager.setReverseLayout(true);
   recyclerView.setLayoutManager(mLayoutManager);
   mAdapter = new ConversationAdapter(this, conversationDisplay);
   recyclerView.setAdapter(mAdapter);
 }
 @Override
 public void setSettingsOnRecyclerView() {
   viewHolder.rvChat.setHasFixedSize(true);
   viewHolder.rvChat.setItemAnimator(new DefaultItemAnimator());
   LinearLayoutManager mLayoutManager = new LinearLayoutManager(mContext);
   mLayoutManager.setReverseLayout(true);
   mLayoutManager.setStackFromEnd(true);
   viewHolder.rvChat.setLayoutManager(mLayoutManager);
   viewHolder.rvChat.addItemDecoration(
       new DividerItemDecoration(mContext, DividerItemDecoration.VERTICAL_LIST));
 }
Example #3
0
  private void init(View view) {
    ((TextView) view.findViewById(R.id.text_view_stats_fragment_title))
        .setText(Player.getInstance().getName() + "'s Stats");
    RecyclerView recycler = (RecyclerView) view.findViewById(R.id.recycler_view_stats_game);
    recycler.setLayoutManager(new LinearLayoutManager(getContext()));
    mAdapter =
        new FirebaseRecyclerAdapter<String, GameStatsViewHolder>(
            String.class,
            R.layout.card_game_stats,
            GameStatsViewHolder.class,
            LaserTagApplication.firebaseReference
                .child("users")
                .child(LaserTagApplication.getUid())
                .child("previousGames")) {

          @Override
          public void populateViewHolder(
              final GameStatsViewHolder holder, final String gameKey, final int position) {
            LaserTagApplication.firebaseReference
                .child("finishedGames")
                .child(gameKey)
                .addListenerForSingleValueEvent(
                    new ValueEventListener() {
                      @Override
                      public void onDataChange(DataSnapshot dataSnapshot) {
                        final DBGame dbGame = dataSnapshot.getValue(DBGame.class);
                        if (dbGame != null) {
                          holder.gameName.setText(
                              dbGame.getHost() + "'s " + dbGame.getGameType().toString());
                          DateFormat dateFormat = new SimpleDateFormat("MM/dd/yy");
                          holder.gameDate.setText(dateFormat.format(dbGame.getDate()));
                          DBPlayer dbPlayer =
                              dbGame
                                  .findPlayer(Player.getInstance().getName())
                                  .getPlayers()
                                  .get(Player.getInstance().getName());
                          holder.playerScore.setText(
                              "Score: " + dbPlayer.getPlayerStats().getScore());
                          holder.playerKD.setText(
                              "KD: "
                                  + dbPlayer.getPlayerStats().getKills()
                                  + " / "
                                  + dbPlayer.getPlayerStats().getDeaths());
                          holder.playerHP.setText(
                              "HP: "
                                  + String.format(
                                      "%.2f", dbPlayer.getPlayerStats().getHitPercentage() * 100)
                                  + "%");
                          holder.playerStatsView.setBackgroundColor(
                              Color.HSVToColor(136, dbPlayer.getPlayerStats().getColor()));

                          holder.itemView.setOnClickListener(
                              new View.OnClickListener() {
                                @Override
                                public void onClick(View v) {
                                  StatsDialogFragment dialog = new StatsDialogFragment();
                                  dialog.setDBGame(dbGame, gameKey);
                                  dialog.show(
                                      getActivity().getSupportFragmentManager(),
                                      "stats_dialog_fragment");
                                }
                              });
                        }
                      }

                      @Override
                      public void onCancelled(FirebaseError firebaseError) {}
                    });
          }
        };
    LinearLayoutManager manager = new LinearLayoutManager(getContext());
    manager.setReverseLayout(true);
    manager.setStackFromEnd(true);
    recycler.setLayoutManager(manager);
    recycler.setAdapter(mAdapter);
  }
  @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();
          }
        });
  }
Example #5
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_chat);

    // Registrando CHAT no observer
    this.mMessageSubject = MessageSubject.getInstance();
    this.mMessageSubject.attach(this);

    // Instancias
    this.mBD = new BD(this);
    this.mFirebase = new Firebase(Util.FIREBASE_URL);
    this.mListMessage = new ArrayList<Message>();
    this.messageDAO = new MessageDAO(this);

    // Referências
    mNewMessage = (EditText) findViewById(R.id.et_newMessage);
    mRecyclerView = (RecyclerView) findViewById(R.id.rv_listMsg);

    // Pegando o nome
    String nomeChatAtivo = getIntent().getStringExtra("nome").toString();
    // Pegando o numero
    mNumeroChatAtivo = getIntent().getStringExtra("numero").toString();

    // Mudando o status da mensagem para lida
    messageDAO.novasMensagensLidas(mNumeroChatAtivo);
    // Buscando o log
    this.mListMessage = messageDAO.getLog(mNumeroChatAtivo);

    Toolbar toolbar = (Toolbar) findViewById(R.id.tbChat);
    // Setando como titulo e subtitulo
    toolbar.setTitle(nomeChatAtivo);
    toolbar.setSubtitle("online");
    setSupportActionBar(toolbar);

    // Ativando o botao voltar
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    // Ativando a foto que fica ao lado do botao voltar
    getSupportActionBar().setDisplayShowHomeEnabled(false);

    // Criando um LayoutManager
    LinearLayoutManager llm = new LinearLayoutManager(this);
    llm.setReverseLayout(false);
    llm.setOrientation(LinearLayoutManager.VERTICAL);

    // Setando os atributos do RecyclerView
    // mRecyclerView.setScrollContainer(true);
    mRecyclerView.setHasFixedSize(
        true); // Informa que o tamanho do recyclerView não vai mudar, ajuda na otimização.
    mRecyclerView.setLayoutManager(llm); // Setando o layoutmanager no recyclerview

    // Criando e passando a lista de mensagens para o adapter
    chatAdapter = new ChatAdapter(mListMessage, this, this);

    // Setando o Adapter no RecyclerView
    mRecyclerView.setAdapter(chatAdapter);

    // Caso a lista de mensagem esteja vazia, esconde o textview com a frase
    if (this.mListMessage.size() > 0) {
      findViewById(R.id.empty).setVisibility(View.INVISIBLE);
      mRecyclerView.getLayoutManager().scrollToPosition(mListMessage.size() - 1);
    }
  }