Advertisement
Guest User

Untitled

a guest
Sep 2nd, 2016
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.98 KB | None | 0 0
  1. <com.atvtremote.NotFocusableScrollView
  2. android:id="@+id/messages_scroll"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:nestedScrollingEnabled="true"
  6. android:layout_above="@+id/send_panel"
  7. android:background="@android:color/transparent"
  8. android:padding="5dp">
  9.  
  10. <LinearLayout
  11. android:id="@+id/messages"
  12. android:layout_width="match_parent"
  13. android:layout_height="match_parent"
  14. android:layout_gravity="bottom"
  15. android:animateLayoutChanges="true"
  16. android:orientation="vertical"/>
  17.  
  18. </com.atvtremote.NotFocusableScrollView>
  19.  
  20. private void addMessage(String message, String userName, int step) {
  21. View v = activity.getLayoutInflater().inflate(R.layout.chat_msg_item, null);
  22. TextView name = (TextView) v.findViewById(R.id.user_name);
  23. TextView msg = (TextView) v.findViewById(R.id.msg_body);
  24. LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams
  25. .WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
  26. params.setMargins(0, 5, 0, 5);
  27. if (messageIds.contains(messageId)) {
  28. params.gravity = Gravity.LEFT;
  29. v.setBackground(context.getResources().getDrawable(R.drawable.chat_msg_me));
  30. messageIds.remove(messageId);
  31. } else {
  32. params.gravity = Gravity.RIGHT;
  33. }
  34. if (messageIds.size() == 0) {
  35. infoSending.setVisibility(View.GONE);
  36. }
  37. name.setText("@" + userName);
  38. msg.setText(message);
  39. switch (step) {
  40. case 0:
  41. msg.setTextColor(context.getResources()
  42. .getColor(android.R.color.holo_green_dark));
  43. break;
  44. case 1:
  45. msg.setTextColor(context.getResources()
  46. .getColor(android.R.color.holo_red_dark));
  47. break;
  48. case 2:
  49. msg.setTextColor(Color.BLACK);
  50. break;
  51. }
  52. v.setLayoutParams(params);
  53. v.requestLayout();
  54. messages.addView(v);
  55. // if (messages.getHeight() > (messagesScroll.getHeight()/2)) {
  56. // messages.removeViewAt(0);
  57. // }
  58. if ((messages.getHeight()+100) > messagesScroll.getHeight()) {
  59. messages.removeViewAt(0);
  60. }
  61. }
  62.  
  63. public class NotFocusableScrollView extends ScrollView {
  64.  
  65. public NotFocusableScrollView(Context context) {
  66. super(context);
  67. }
  68.  
  69. public NotFocusableScrollView(Context context, AttributeSet attrs) {
  70. super(context, attrs);
  71. }
  72.  
  73. public NotFocusableScrollView(Context context, AttributeSet attrs, int defStyle) {
  74. super(context, attrs, defStyle);
  75. }
  76.  
  77. @Override
  78. protected boolean onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect) {
  79. return true;
  80. }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement