Esempio n. 1
0
  public boolean sendChatMessage() {
    app = new RingToAPI();
    ArrayList<String> to_num = new ArrayList<String>();
    to_num.add(to_number.replace('+', ' ').trim());
    RingToApplication singleton = (RingToApplication) getApplicationContext();
    String access_token = singleton.getAccessToken();
    token = singleton.getToken();

    app.setAPI(
        this,
        token,
        access_token,
        from_number.replace('+', ' ').trim(),
        new ArrayList<String>(),
        chatText.getText().toString(),
        to_num);
    side = false;
    chatArrayAdapter.add(new Message(side, chatText.getText().toString()));
    chatText.setText("");

    return true;
  }
Esempio n. 2
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_chat);

    buttonSend = (Button) findViewById(R.id.buttonSend);
    listView = (ListView) findViewById(R.id.listView1);
    datasource = new RingToDataSource(this);
    datasource.open();

    chatArrayAdapter =
        new ChatArrayAdapter(this.getApplicationContext(), R.layout.activity_chat_singlemessage);
    listView.setAdapter(chatArrayAdapter);
    listView.setDivider(null);
    chatText = (EditText) findViewById(R.id.chatText);
    chatText.setOnKeyListener(
        new View.OnKeyListener() {
          public boolean onKey(View v, int keyCode, KeyEvent event) {
            if ((event.getAction() == KeyEvent.ACTION_DOWN)
                && (keyCode == KeyEvent.KEYCODE_ENTER)) {
              return sendChatMessage();
            }

            return false;
          }
        });

    buttonSend.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View arg0) {
            sendChatMessage();
          }
        });

    //        else
    //        {
    //            message_list = new ArrayList<Message>(datasource.getAllMessages());
    //            chatArrayAdapter.addListOfMessages(message_list);
    //        }

    //        FragmentManager managerFragment = getSupportFragmentManager();
    //        app = (RingToAPI) managerFragment.findFragmentByTag(String.valueOf(0));
    //
    //        if(app == null)
    //        {
    //            app = new RingToAPI();
    to_number = getIntent().getExtras().getString("to_number");
    from_number = getIntent().getExtras().getString("from_number");

    //            app.setAPI(this, token);
    //            managerFragment.beginTransaction().add(app, String.valueOf(0)).commit();
    //        }

    listView.setTranscriptMode(AbsListView.TRANSCRIPT_MODE_ALWAYS_SCROLL);
    listView.setAdapter(chatArrayAdapter);

    // to scroll the list view to bottom on data change
    chatArrayAdapter.registerDataSetObserver(
        new DataSetObserver() {
          @Override
          public void onChanged() {
            super.onChanged();
            listView.setSelection(chatArrayAdapter.getCount() - 1);
          }
        });

    chatArrayAdapter.addListOfMessages(datasource.getChatThread(to_number, from_number));

    //        if (savedInstanceState != null)
    //        {
    //            RingToApplication singleton = (RingToApplication) getApplicationContext();
    //            token = singleton.getToken();
    //            app = new RingToAPI();
    //            app.setToken(token);
    //        }
    //
    //        else
    //        {
    //            // Takes the previous saved list of messages on screen and appends them to
    //            // the current message list on screen.
    ////            message_list = savedInstanceState.getParcelableArrayList("here");
    ////            chatArrayAdapter.addListOfMessages(message_list);
    //        }

    //        Toast.makeText(getApplicationContext(), Integer.toString(messages.length()),
    // Toast.LENGTH_LONG);
    //        app.pullMessages(getActivity());

  }