Example usage for android.widget ListView setStackFromBottom

List of usage examples for android.widget ListView setStackFromBottom

Introduction

In this page you can find the example usage for android.widget ListView setStackFromBottom.

Prototype

public void setStackFromBottom(boolean stackFromBottom) 

Source Link

Document

When stack from bottom is set to true, the list fills its content starting from the bottom of the view.

Usage

From source file:com.coderdojo.libretalk.MainActivity.java

private final void printMsg(final String message) {
    ArrayAdapter<SpannableString> adapter = new ArrayAdapter<SpannableString>(this,
            android.R.layout.simple_list_item_1, mMessageListArray);
    ListView listView = (ListView) findViewById(R.id.message_list);
    listView.setAdapter(adapter);//from  ww  w .  j a v a2s .c  o  m
    listView.setStackFromBottom(true);

    mMessageListArray.add(new SpannableString(message));
    adapter.notifyDataSetChanged();
}

From source file:org.solovyev.android.messenger.messages.MessagesFragment.java

@Override
protected void fillListView(@Nonnull ListView lv, @Nonnull Context context) {
    super.fillListView(lv, context);

    lv.setDividerHeight(0);//from   ww  w . ja v a2 s .  c o  m
    lv.setStackFromBottom(true);
    lv.setFastScrollEnabled(false);
}

From source file:com.coderdojo.libretalk.MainActivity.java

public void addMessage(View view) {
    EditText messageEditText = (EditText) findViewById(R.id.edit_message);
    String message = messageEditText.getText().toString();
    messageEditText.setText("");

    ArrayAdapter<SpannableString> adapter = new ArrayAdapter<SpannableString>(this,
            android.R.layout.simple_list_item_1, mMessageListArray);
    ListView listView = (ListView) findViewById(R.id.message_list);
    listView.setAdapter(adapter);//from  www  .j av  a 2  s.  c  om
    listView.setStackFromBottom(true);

    //mMessageListArray.add(new String(message));
    //adapter.notifyDataSetChanged();

    //XXX NETWORKING CODE BEGIN
    if (!message.isEmpty()) {
        if (message.startsWith(".nick")) {
            this.nick = message.substring(5);
            printMsg("\t >> Changed your nickname to " + this.nick);
            return;
        }

        final LibretalkMessageData data = new LibretalkMessageData(this.nick, message);
        this.sender.send(LibretalkMessageData.serialize(data).getBytes(), this.connection.getUserTag());
    }
    //XXX NETWORKING CODE END
}

From source file:com.coderdojo.libretalk.MainActivity.java

private final void printMsg(final LibretalkMessageData message) {
    ArrayAdapter<SpannableString> adapter = new ArrayAdapter<SpannableString>(this,
            android.R.layout.simple_list_item_1, mMessageListArray);
    ListView listView = (ListView) findViewById(R.id.message_list);
    listView.setAdapter(adapter);//w  w w .j a va 2s  .c o  m
    listView.setStackFromBottom(true);

    final String sourceMessage = message.getSenderTag() + ": " + message.getData();
    final SpannableString formattedText = new SpannableString(sourceMessage);

    if (message.getData().startsWith(">")) {

        formattedText.setSpan(
                new ForegroundColorSpan(LibretalkMessageData.getColorFromString(message.getSenderTag())),
                sourceMessage.indexOf(message.getSenderTag()),
                sourceMessage.indexOf(message.getSenderTag()) + message.getSenderTag().length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

        formattedText.setSpan(new ForegroundColorSpan(Color.rgb(120, 153, 34)),
                sourceMessage.indexOf(message.getData()),
                sourceMessage.indexOf(message.getData()) + message.getData().length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    } else {

        formattedText.setSpan(
                new ForegroundColorSpan(LibretalkMessageData.getColorFromString(message.getSenderTag())),
                sourceMessage.indexOf(message.getSenderTag()),
                sourceMessage.indexOf(message.getSenderTag()) + message.getSenderTag().length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    }

    mMessageListArray.add(formattedText);
    adapter.notifyDataSetChanged();
}

From source file:me.myatminsoe.myansms.MessageListActivity.java

/**
 * Parse data pushed by {@link Intent}./*  w w w . j av a 2 s.c o m*/
 *
 * @param intent {@link Intent}
 */
private void parseIntent(final Intent intent) {

    if (intent == null) {
        return;
    }

    needContactUpdate = true;

    uri = intent.getData();
    if (uri != null) {
        if (!uri.toString().startsWith(URI)) {
            uri = Uri.parse(URI + uri.getLastPathSegment());
        }
    } else {
        final long tid = intent.getLongExtra("thread_id", -1L);
        uri = Uri.parse(URI + tid);
        if (tid < 0L) {
            try {
                startActivity(ConversationListActivity.getComposeIntent(this, null, false));
            } catch (ActivityNotFoundException e) {
                Log.e(TAG, "activity not found", e);
                Toast.makeText(this, R.string.error_conv_null, Toast.LENGTH_LONG).show();
            }
            finish();
            return;
        }
    }

    int threadId;
    try {
        threadId = Integer.parseInt(uri.getLastPathSegment());
    } catch (NumberFormatException e) {
        Log.e(TAG, "unable to parse thread id: ", e);
        Toast.makeText(this, R.string.error_conv_null, Toast.LENGTH_LONG).show();
        finish();
        return;
    }
    Conversation c;
    try {
        c = Conversation.getConversation(this, threadId, true);
        threadId = c.getThreadId(); // force a NPE :x
    } catch (NullPointerException e) {

        Toast.makeText(this, R.string.error_conv_null, Toast.LENGTH_LONG).show();
        finish();
        return;
    }

    conv = c;
    final Contact contact = c.getContact();
    try {
        contact.update(this, false, true);
    } catch (NullPointerException e) {
        Log.e(TAG, "updating contact failed", e);
    }
    boolean showKeyboard = intent.getBooleanExtra("showKeyboard", false);

    final ListView lv = getListView();
    lv.setStackFromBottom(true);

    MessageAdapter adapter = new MessageAdapter(this, uri);
    setListAdapter(adapter);

    String displayName = contact.getDisplayName();
    setTitle(displayName);
    String number = contact.getNumber();
    if (displayName.equals(number)) {
        getSupportActionBar().setSubtitle(null);
    } else {
        getSupportActionBar().setSubtitle(number);
    }

    final String body = intent.getStringExtra(Intent.EXTRA_TEXT);
    if (!TextUtils.isEmpty(body)) {
        etText.setText(body);
        showKeyboard = true;
    }

    if (showKeyboard) {
        etText.requestFocus();
    }

    setRead();
}

From source file:de.ub0r.android.smsdroid.MessageListActivity.java

/**
 * Parse data pushed by {@link Intent}./*from  ww  w .  jav a  2s  .c o  m*/
 * 
 * @param intent
 *            {@link Intent}
 */
private void parseIntent(final Intent intent) {
    Log.d(TAG, "parseIntent(" + intent + ")");
    if (intent == null) {
        return;
    }
    Log.d(TAG, "got action: " + intent.getAction());
    Log.d(TAG, "got uri: " + intent.getData());

    this.needContactUpdate = true;

    this.uri = intent.getData();
    if (this.uri != null) {
        if (!this.uri.toString().startsWith(URI)) {
            this.uri = Uri.parse(URI + this.uri.getLastPathSegment());
        }
    } else {
        final long tid = intent.getLongExtra("thread_id", -1L);
        this.uri = Uri.parse(URI + tid);
        if (tid < 0L) {
            try {
                this.startActivity(ConversationListActivity.getComposeIntent(this, null));
            } catch (ActivityNotFoundException e) {
                Log.e(TAG, "activity not found", e);
                Toast.makeText(this, R.string.error_conv_null, Toast.LENGTH_LONG).show();
            }
            this.finish();
            return;
        }
    }

    final int threadId = Integer.parseInt(this.uri.getLastPathSegment());
    final Conversation c = Conversation.getConversation(this, threadId, true);
    this.conv = c;

    if (c == null) {
        Toast.makeText(this, R.string.error_conv_null, Toast.LENGTH_LONG).show();
        this.finish();
        return;
    }

    final Contact contact = c.getContact();
    contact.update(this, false, true);

    Log.d(TAG, "address: " + contact.getNumber());
    Log.d(TAG, "name: " + contact.getName());
    Log.d(TAG, "displayName: " + contact.getDisplayName());

    final ListView lv = this.getListView();
    lv.setStackFromBottom(true);

    MessageAdapter adapter = new MessageAdapter(this, this.uri);
    this.setListAdapter(adapter);

    String displayName = contact.getDisplayName();
    this.setTitle(displayName);
    String number = contact.getNumber();
    if (displayName.equals(number)) {
        this.getSupportActionBar().setSubtitle(null);
    } else {
        this.getSupportActionBar().setSubtitle(number);
    }

    this.setContactIcon(contact);

    final String body = intent.getStringExtra(Intent.EXTRA_TEXT);
    if (!TextUtils.isEmpty(body)) {
        this.etText.setText(body);
    }

    this.setRead();
}

From source file:com.android.calculator2.FloatingCalculatorPageAdapter.java

private void setUpHistory(ListView historyView) {
    FloatingHistoryAdapter.OnHistoryItemClickListener listener = new FloatingHistoryAdapter.OnHistoryItemClickListener() {
        @Override/*  w  ww.ja  va2s .  c om*/
        public void onHistoryItemClick(HistoryEntry entry) {
            int deleteMode = mLogic.getDeleteMode();
            if (mDisplay.getText().isEmpty()) {
                deleteMode = Logic.DELETE_MODE_CLEAR;
            }

            mDisplay.insert(entry.getEdited());
            mLogic.setDeleteMode(deleteMode);
        }
    };

    FloatingHistoryAdapter historyAdapter = new FloatingHistoryAdapter(mContext, mHistory);
    historyAdapter.setOnHistoryItemClickListener(listener);
    mHistory.setObserver(historyAdapter);
    historyView.setAdapter(historyAdapter);
    historyView.setStackFromBottom(true);
    historyView.setTranscriptMode(ListView.TRANSCRIPT_MODE_ALWAYS_SCROLL);
}

From source file:com.nnm.smsviet.MessageListActivity.java

/**
 * Parse data pushed by {@link Intent}.//from  w ww.  j a v a 2s.  co m
 * 
 * @param intent
 *            {@link Intent}
 */
private void parseIntent(final Intent intent) {
    Log.d(TAG, "parseIntent(" + intent + ")");
    if (intent == null) {
        return;
    }
    Log.d(TAG, "got action: " + intent.getAction());
    Log.d(TAG, "got uri: " + intent.getData());

    this.needContactUpdate = true;

    this.uri = intent.getData();
    if (this.uri != null) {
        if (!this.uri.toString().startsWith(URI)) {
            this.uri = Uri.parse(URI + this.uri.getLastPathSegment());
        }
    } else {
        final long tid = intent.getLongExtra("thread_id", -1L);
        this.uri = Uri.parse(URI + tid);
        if (tid < 0L) {
            try {
                this.startActivity(ConversationListActivity.getComposeIntent(this, null));
            } catch (ActivityNotFoundException e) {
                Log.e(TAG, "activity not found", e);
                Toast.makeText(this, R.string.error_conv_null, Toast.LENGTH_LONG).show();
            }
            this.finish();
            return;
        }
    }
    this.getLastPathSegment = Integer.parseInt(this.uri.getLastPathSegment());
    final int threadId = Integer.parseInt(this.uri.getLastPathSegment());
    final Conversation c = Conversation.getConversation(this, threadId, true);
    this.conv = c;

    if (c == null) {
        Toast.makeText(this, R.string.error_conv_null, Toast.LENGTH_LONG).show();
        this.finish();
        return;
    }

    final Contact contact = c.getContact();
    contact.update(this, false, true);

    Log.d(TAG, "address: " + contact.getNumber());
    Log.d(TAG, "name: " + contact.getName());
    Log.d(TAG, "displayName: " + contact.getDisplayName());

    final ListView lv = this.getListView();
    lv.setStackFromBottom(true);

    MessageAdapter adapter = new MessageAdapter(this, this.uri);
    this.setListAdapter(adapter);

    String displayName = contact.getDisplayName();
    this.setTitle(displayName);
    String number = contact.getNumber();
    if (displayName.equals(number)) {
        this.getSupportActionBar().setSubtitle(null);
    } else {
        this.getSupportActionBar().setSubtitle(number);
    }

    this.setContactIcon(contact);

    final String body = intent.getStringExtra(Intent.EXTRA_TEXT);
    if (!TextUtils.isEmpty(body)) {
        this.etText.setText(body);
    }

    this.setRead();
}

From source file:it.ciopper90.gojack2.MessageListActivity.java

/**
 * Parse data pushed by {@link Intent}.//from  ww w .  j a v a2s  .c om
 * 
 * @param intent
 *            {@link Intent}
 */
private void parseIntent(final Intent intent) {
    Log.d(TAG, "parseIntent(" + intent + ")");
    if (intent == null) {
        return;
    }
    Log.d(TAG, "got action: " + intent.getAction());
    Log.d(TAG, "got uri: " + intent.getData());

    this.needContactUpdate = true;

    this.uri = intent.getData();
    if (this.uri != null) {
        if (!this.uri.toString().startsWith(URI)) {
            this.uri = Uri.parse(URI + this.uri.getLastPathSegment());
        }
    } else {
        final long tid = intent.getLongExtra("thread_id", -1L);
        this.uri = Uri.parse(URI + tid);
        if (tid < 0L) {
            try {
                // this.startActivity(ConversationListActivity.getComposeIntent(this,
                // null));
            } catch (ActivityNotFoundException e) {
                Log.e(TAG, "activity not found", e);
                Toast.makeText(this, R.string.error_conv_null, Toast.LENGTH_LONG).show();
            }
            this.finish();
            return;
        }
    }

    final int threadId = Integer.parseInt(this.uri.getLastPathSegment());
    final Conversation c = Conversation.getConversation(this, threadId, true);
    this.conv = c;

    if (c == null) {
        Toast.makeText(this, R.string.error_conv_null, Toast.LENGTH_LONG).show();
        this.finish();
        return;
    }

    final Contact contact = c.getContact();
    contact.update(this, false, true);

    Log.d(TAG, "address: " + contact.getNumber());
    Log.d(TAG, "name: " + contact.getName());
    Log.d(TAG, "displayName: " + contact.getDisplayName());

    final ListView lv = this.getListView();
    lv.setStackFromBottom(true);

    MessageAdapter adapter = new MessageAdapter(this, this.uri);
    this.setListAdapter(adapter);

    String displayName = contact.getDisplayName();
    this.setTitle(displayName);
    number = contact.getNumber();
    if (displayName.equals(number)) {
        this.getSupportActionBar().setSubtitle(null);
        number = contact.getDisplayName();
    } else {
        this.getSupportActionBar().setSubtitle(number);
    }
    // this.getSupportActionBar().setDisplayUseLogoEnabled(false);
    // this.getSupportActionBar().setDisplayHomeAsUpEnabled(false);
    this.getSupportActionBar().setDisplayShowHomeEnabled(false);

    // this.spinner = WSInterface.setSpinner(this);
    if (MessageListActivity.alert == null) {
        MessageListActivity.alert = "";
    }
    // this.getSupportActionBar().setIcon(R.drawable.ic_menu_star);
    // this.getSupportActionBar().
    // this.ws = new WorkServizio(this.getApplicationContext());

    // service = this.ws.caricaServizio();
    // this.spinner = new Spinner(this);
    // ArrayList<String> lista = new ArrayList<String>();
    // for (int i = 0; i < service.size(); i++) {
    // lista.add(service.get(i).getName());
    // }
    // lista.add("a");
    // lista.add("b");
    // lista.add("c");

    // this.spinneradapter = new ArrayAdapter<String>(this,
    // R.layout.textview, lista);
    // this.spinner.setAdapter(this.spinneradapter);

    // String serv = WSInterface.ServizioNumero(number);
    // if (serv != null) {
    // int a = lista.indexOf(serv);
    // lista.indexOf(serv));
    // }
    // TODO attach to an adapter of some sort
    // this.getSupportActionBar().setCustomView(this.spinner);
    // this.getSupportActionBar().setDisplayShowCustomEnabled(true);
    // this.setContactIcon(contact);

    if (MessageListActivity.alert.equals("captcha")) {
        this.captcha();// Dialog.RestoreDialog(this, this.alert);
    } else {
        if (MessageListActivity.alert.equals("error")) {
            this.error(MessageListActivity.errore);
        } else {
            if (!MessageListActivity.alert.equals("")) {
                MessageListActivity.pd = Dialog.ProgDialog(this, MessageListActivity.alert);
                MessageListActivity.pd.show();
            }
        }
    }

    final String body = intent.getStringExtra(Intent.EXTRA_TEXT);
    if (!TextUtils.isEmpty(body)) {
        MessageListActivity.etText.setText(body);
    }

    this.setRead();
}

From source file:com.juick.android.ThreadFragment.java

private void onWebSocketMessages(final ArrayList<JuickMessage> messages) {
    getActivity().runOnUiThread(new Runnable() {
        public void run() {
            // don't scroll
            ListView listView = null;
            try {
                listView = getListView();
            } catch (Exception e) {
                // view not yet created
                return;
            }/*from w ww .  j a v a  2s.co  m*/
            listView.setTranscriptMode(ListView.TRANSCRIPT_MODE_NORMAL);
            listView.setStackFromBottom(false);
            //
            if (sp.getBoolean("current_vibration_enabled", true)) {
                if (!paused) {
                    ((Vibrator) getActivity().getSystemService(Activity.VIBRATOR_SERVICE)).vibrate(250);
                }
            }
            if (listAdapter.getCount() > 0) {
                for (JuickMessage message : messages) {
                    if (message.getReplyTo() != 0 && !message.Text.startsWith("@")) {
                        for (int z = 0; z < listAdapter.getCount(); z++) {
                            JuickMessage item = listAdapter.getItem(z);
                            if (item != null && item.getRID() == message.getReplyTo()) {
                                message.Text = "@" + item.User.UName + " " + message.Text;
                            }
                        }
                    }
                }
                listAdapter.addAllMessages(messages);
                if (getActivity() instanceof ThreadActivity) {
                    ThreadActivity ta = (ThreadActivity) getActivity();
                    Editable text = ta.etMessage.getText();
                    for (JuickMessage message : messages) {
                        if (message.Text.contains(text)) {
                            if (ta.replyInProgress != null) {
                                ta.replyInProgress.preliminarySuccess();
                            }
                        }
                    }
                }
            }
            xmppServiceServiceGetter.getService(new Utils.ServiceGetter.Receiver<XMPPService>() {
                @Override
                public void withService(XMPPService service) {
                    for (JuickMessage message : messages) {
                        service.removeMessages(message.getMID(), false);
                    }
                }
            });
            Utils.ServiceGetter<DatabaseService> databaseGetter = new Utils.ServiceGetter<DatabaseService>(
                    getActivity(), DatabaseService.class);
            databaseGetter.getService(new Utils.ServiceGetter.Receiver<DatabaseService>() {
                @Override
                public void withService(DatabaseService service) {
                    service.maybeSaveMessages(messages);
                    super.withService(service);
                }
            });
            try {
                listAdapter.getItem(1).Text = getResources().getString(R.string.Replies) + " ("
                        + Integer.toString(listAdapter.getCount() - 2) + ")";
            } catch (Throwable ex) {
                // web socket came earlier than body itself!
            }
        }
    });
}