Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <ListView
- android:id="@+id/lstMessages"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:transcriptMode="alwaysScroll"
- android:layout_above="@+id/relSendMessage"
- android:layout_below="@+id/relRecipient"
- android:background="@drawable/bg_shadow"
- android:padding="0dip"
- android:divider="@null"
- android:dividerHeight="0dp" android:stackFromBottom="true" tools:listitem="@layout/message_left"/
- Adapter Class Code :
- public class ChatAdapter extends BaseAdapter implements OnCompletionListener{
- Context context;
- TextView txtmsg;
- ImageView imgSender ,playaudio;
- TextView txtSender;
- TextView txtDate;
- VideoView videosender;
- SeekBar seekbar;
- MediaPlayer mp;
- private boolean bVideoIsBeingTouched = false;
- private Handler mHandler = new Handler();
- ArrayList<HashMap<String, String>> data;
- public ChatAdapter(Context context,
- ArrayList<HashMap<String, String>> arraylist) {
- // TODO Auto-generated constructor stub
- this.context = context;
- data = arraylist;
- }
- @Override
- public int getCount() {
- // TODO Auto-generated method stub
- return data.size();
- }
- @Override
- public int getViewTypeCount() {
- return 2;
- }
- @Override
- public Object getItem(int position) {
- // TODO Auto-generated method stub
- return null;
- }
- @Override
- public long getItemId(int position) {
- // TODO Auto-generated method stub
- return position;
- }
- @Override
- public int getItemViewType(int position) {
- return position;
- }
- @Override
- public View getView( int position, View convertView, ViewGroup parent) {
- // TODO Auto-generated method stub
- HashMap<String, String> resultp = new HashMap<String, String>();
- resultp = data.get(position);
- if (convertView == null) {
- int res = 0;
- if(resultp.get(Tab2.CHAT_MSG).equals("/AUDIO/")&&resultp.get(Tab2.CHAT_TYPE).equals("outgoing"))
- {
- final String path=resultp.get(Tab2.PATH);
- res = R.layout.audioleft;
- LayoutInflater inflater = (LayoutInflater) context
- .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- convertView = inflater.inflate(res, parent, false);
- txtSender = (TextView) convertView.findViewById(R.id.txtSender);
- playaudio = (ImageView) convertView.findViewById(R.id.imageView1);
- seekbar = (SeekBar) convertView.findViewById(R.id.songProgressBar);
- playaudio.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View arg0) {
- getActivity().setVolumeControlStream(android.media.AudioManager.STREAM_MUSIC);
- mp = new MediaPlayer();
- mp.setOnCompletionListener(ChatAdapter.this);
- try {
- playaudio.setBackgroundResource(R.drawable.img_btn_pause);
- mp.setDataSource(path);
- mp.prepare();
- mp.start();
- seekbar.setProgress(0);
- seekbar.setMax(100);
- // Updating progress bar
- updateProgressBar();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- txtDate = (TextView) convertView.findViewById(R.id.txtDate);
- }
- }
- else
- {
- }
- return convertView;
- }
- }
- public void updateProgressBar() {
- mHandler.postDelayed(mUpdateTimeTask, 100);
- }
- /**
- * Background Runnable thread
- * */
- private Runnable mUpdateTimeTask = new Runnable() {
- public void run() {
- long totalDuration = mp.getDuration();
- long currentDuration = mp.getCurrentPosition();
- // Displaying Total Duration time
- // Displaying time completed playing
- );
- // Updating progress bar
- int progress = (int)(getProgressPercentage(currentDuration, totalDuration));
- //Log.d("Progress", ""+progress);
- seekbar.setProgress(progress);
- // Running this thread after 100 milliseconds
- mHandler.postDelayed(this, 100);
- }
- };
- audioleft.xml
- <?xml version="1.0" encoding="utf-8"?>
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:padding="10dp">
- <RelativeLayout android:layout_width="fill_parent" android:layout_height="fill_parent"
- android:layout_marginRight="10dp">
- <TextView
- android:id="@+id/txtSender"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentTop="true"
- android:text="Sender Ipsum"
- android:textSize="16sp"
- android:singleLine="true"
- android:layout_alignParentLeft="true"
- android:paddingLeft="10dp"
- android:paddingBottom="6dp"
- android:textColor="@android:color/black" android:textStyle="bold"/>
- <TextView
- android:id="@+id/txtDate"
- android:layout_alignParentRight="true"
- android:textColor="@color/sinch_purple"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:paddingRight="2dp"
- android:paddingBottom="6dp"
- android:textSize="12sp"
- android:text="14:54"
- android:layout_alignBottom="@+id/txtSender"/>
- <RelativeLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_below="@+id/txtSender"
- android:layout_alignParentLeft="true"
- android:padding="12dp"
- >
- <SeekBar
- android:id="@+id/songProgressBar"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_marginRight="20dp"
- android:layout_marginLeft="20dp"
- android:layout_marginBottom="20dp"
- android:thumb="@drawable/sthumb"
- android:progressDrawable="@drawable/seekbar_progress"
- />
- <!-- android:thumb="@drawable/seek_handler" -->
- <ImageView
- android:id="@+id/imageView1"
- android:layout_width="30dp"
- android:layout_height="30dp"
- android:layout_alignBottom="@+id/songProgressBar"
- android:layout_alignParentLeft="true"
- android:layout_marginLeft="17dp"
- android:background="@drawable/img_btn_play" />
- </RelativeLayout>
- </RelativeLayout>
- </RelativeLayout>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement