Advertisement
Guest User

Untitled

a guest
Jul 29th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.70 KB | None | 0 0
  1. <ListView
  2. android:id="@+id/lstMessages"
  3. android:layout_width="match_parent"
  4. android:layout_height="wrap_content"
  5. android:transcriptMode="alwaysScroll"
  6. android:layout_above="@+id/relSendMessage"
  7. android:layout_below="@+id/relRecipient"
  8. android:background="@drawable/bg_shadow"
  9. android:padding="0dip"
  10. android:divider="@null"
  11. android:dividerHeight="0dp" android:stackFromBottom="true" tools:listitem="@layout/message_left"/
  12.  
  13.  
  14. Adapter Class Code :
  15. public class ChatAdapter extends BaseAdapter implements OnCompletionListener{
  16. Context context;
  17. TextView txtmsg;
  18. ImageView imgSender ,playaudio;
  19. TextView txtSender;
  20. TextView txtDate;
  21. VideoView videosender;
  22. SeekBar seekbar;
  23. MediaPlayer mp;
  24. private boolean bVideoIsBeingTouched = false;
  25. private Handler mHandler = new Handler();
  26. ArrayList<HashMap<String, String>> data;
  27. public ChatAdapter(Context context,
  28. ArrayList<HashMap<String, String>> arraylist) {
  29. // TODO Auto-generated constructor stub
  30. this.context = context;
  31. data = arraylist;
  32.  
  33. }
  34.  
  35. @Override
  36. public int getCount() {
  37. // TODO Auto-generated method stub
  38. return data.size();
  39. }
  40. @Override
  41. public int getViewTypeCount() {
  42. return 2;
  43. }
  44. @Override
  45. public Object getItem(int position) {
  46. // TODO Auto-generated method stub
  47. return null;
  48. }
  49.  
  50. @Override
  51. public long getItemId(int position) {
  52. // TODO Auto-generated method stub
  53. return position;
  54. }
  55.  
  56.  
  57. @Override
  58. public int getItemViewType(int position) {
  59.  
  60. return position;
  61. }
  62. @Override
  63. public View getView( int position, View convertView, ViewGroup parent) {
  64. // TODO Auto-generated method stub
  65.  
  66. HashMap<String, String> resultp = new HashMap<String, String>();
  67. resultp = data.get(position);
  68.  
  69. if (convertView == null) {
  70.  
  71. int res = 0;
  72. if(resultp.get(Tab2.CHAT_MSG).equals("/AUDIO/")&&resultp.get(Tab2.CHAT_TYPE).equals("outgoing"))
  73. {
  74.  
  75. final String path=resultp.get(Tab2.PATH);
  76. res = R.layout.audioleft;
  77. LayoutInflater inflater = (LayoutInflater) context
  78. .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  79. convertView = inflater.inflate(res, parent, false);
  80. txtSender = (TextView) convertView.findViewById(R.id.txtSender);
  81. playaudio = (ImageView) convertView.findViewById(R.id.imageView1);
  82. seekbar = (SeekBar) convertView.findViewById(R.id.songProgressBar);
  83.  
  84.  
  85.  
  86. playaudio.setOnClickListener(new View.OnClickListener() {
  87.  
  88. @Override
  89. public void onClick(View arg0) {
  90.  
  91.  
  92. getActivity().setVolumeControlStream(android.media.AudioManager.STREAM_MUSIC);
  93. mp = new MediaPlayer();
  94. mp.setOnCompletionListener(ChatAdapter.this);
  95.  
  96. try {
  97. playaudio.setBackgroundResource(R.drawable.img_btn_pause);
  98. mp.setDataSource(path);
  99. mp.prepare();
  100. mp.start();
  101.  
  102. seekbar.setProgress(0);
  103. seekbar.setMax(100);
  104.  
  105. // Updating progress bar
  106. updateProgressBar();
  107. } catch (Exception e) {
  108. e.printStackTrace();
  109. }
  110.  
  111.  
  112.  
  113. }
  114.  
  115. });
  116. txtDate = (TextView) convertView.findViewById(R.id.txtDate);
  117.  
  118.  
  119.  
  120. }
  121. }
  122. else
  123. {
  124.  
  125. }
  126. return convertView;
  127. }
  128. }
  129. public void updateProgressBar() {
  130. mHandler.postDelayed(mUpdateTimeTask, 100);
  131. }
  132.  
  133. /**
  134. * Background Runnable thread
  135. * */
  136. private Runnable mUpdateTimeTask = new Runnable() {
  137. public void run() {
  138. long totalDuration = mp.getDuration();
  139. long currentDuration = mp.getCurrentPosition();
  140.  
  141. // Displaying Total Duration time
  142.  
  143. // Displaying time completed playing
  144. );
  145.  
  146. // Updating progress bar
  147. int progress = (int)(getProgressPercentage(currentDuration, totalDuration));
  148. //Log.d("Progress", ""+progress);
  149. seekbar.setProgress(progress);
  150.  
  151. // Running this thread after 100 milliseconds
  152. mHandler.postDelayed(this, 100);
  153. }
  154. };
  155.  
  156. audioleft.xml
  157.  
  158. <?xml version="1.0" encoding="utf-8"?>
  159.  
  160. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  161. android:layout_width="match_parent"
  162. android:layout_height="wrap_content"
  163. android:padding="10dp">
  164.  
  165. <RelativeLayout android:layout_width="fill_parent" android:layout_height="fill_parent"
  166. android:layout_marginRight="10dp">
  167.  
  168. <TextView
  169. android:id="@+id/txtSender"
  170. android:layout_width="wrap_content"
  171. android:layout_height="wrap_content"
  172. android:layout_alignParentTop="true"
  173. android:text="Sender Ipsum"
  174. android:textSize="16sp"
  175. android:singleLine="true"
  176. android:layout_alignParentLeft="true"
  177. android:paddingLeft="10dp"
  178. android:paddingBottom="6dp"
  179. android:textColor="@android:color/black" android:textStyle="bold"/>
  180.  
  181. <TextView
  182. android:id="@+id/txtDate"
  183. android:layout_alignParentRight="true"
  184. android:textColor="@color/sinch_purple"
  185. android:layout_width="wrap_content"
  186. android:layout_height="wrap_content"
  187. android:paddingRight="2dp"
  188. android:paddingBottom="6dp"
  189. android:textSize="12sp"
  190. android:text="14:54"
  191. android:layout_alignBottom="@+id/txtSender"/>
  192.  
  193. <RelativeLayout
  194. android:layout_width="match_parent"
  195. android:layout_height="wrap_content"
  196. android:layout_below="@+id/txtSender"
  197. android:layout_alignParentLeft="true"
  198. android:padding="12dp"
  199.  
  200. >
  201. <SeekBar
  202. android:id="@+id/songProgressBar"
  203. android:layout_width="fill_parent"
  204. android:layout_height="wrap_content"
  205. android:layout_marginRight="20dp"
  206. android:layout_marginLeft="20dp"
  207. android:layout_marginBottom="20dp"
  208. android:thumb="@drawable/sthumb"
  209. android:progressDrawable="@drawable/seekbar_progress"
  210. />
  211.  
  212. <!-- android:thumb="@drawable/seek_handler" -->
  213.  
  214.  
  215.  
  216.  
  217. <ImageView
  218. android:id="@+id/imageView1"
  219. android:layout_width="30dp"
  220. android:layout_height="30dp"
  221. android:layout_alignBottom="@+id/songProgressBar"
  222. android:layout_alignParentLeft="true"
  223. android:layout_marginLeft="17dp"
  224. android:background="@drawable/img_btn_play" />
  225.  
  226. </RelativeLayout>
  227. </RelativeLayout>
  228. </RelativeLayout>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement