I also have a micro-trust friend Circle Android implementation _mssql

Source: Internet
Author: User
Tags set background stub

This article examples share a simple circle of friends program, including a list of friends, video recording, preview and upload, pictures can choose to take photos, for your reference, specific content as follows

The friendslistactivity code is as follows

public class Friendslistactivity extends baseactivity implements Onrefreshlistener<listview>, Postlistener {pri 
  Vate Interactionadapter Madapter; 
  Private Pulltorefreshlistview Mrefreshlistview; 
  Private View Mfooter; 
  Private context Mcontext; 
  Private Button Btntopost; 
  protected int mpage = 0; 
  Private Boolean isrefreshing = false; @Override protected void OnCreate (Bundle savedinstancestate) {//TODO auto-generated method stub Super.oncre 
    Ate (savedinstancestate); 
    Setcontentview (r.layout.friends_list); 
    Mcontext=getapplicationcontext (); 
    Madapter = new Interactionadapter (mcontext); 
    Madapter.setlistener (this); 
    Btntopost= (Button) Findviewbyid (r.id.btn_topost); 
    Mrefreshlistview = (Pulltorefreshlistview) Findviewbyid (r.id.friends_list); 
    Friendsapi.getfriendslist (Mcontext, mcallback); 
    Mrefreshlistview.setonrefreshlistener (this); 
Mfooter = Layoutinflater.from (Mcontext). Inflate (r.layout.loading_footer, NULL);Mrefreshlistview.getrefreshableview (). Addfooterview (Mfooter); 
Mrefreshlistview.setadapter (Madapter); 
Mrefreshlistview.setonlastitemvisiblelistener (Mlastlistener); 
    Mrefreshlistview.getrefreshableview (). Setdividerheight (40); 
        Btntopost.setonclicklistener (New Onclicklistener () {@Override public void OnClick (View v) { 
      Myposts (); 
  } 
    }); } protected void Myposts () {new Alertdialog.builder (this). Setitems (New string[]{"Picture", "video", "Text"}, new Dialogin Terface. Onclicklistener () {@Override public void OnClick (Dialoginterface dialog, int which) {inte 
        NT Intent=new Intent (); 
          Switch (which) {case 0:intent.setclass (friendslistactivity.this, Createpostactivity.class); 
        Break 
          Case 1:intent.setclass (Friendslistactivity.this, Recorderactivity.class); 
        Break Case 2:intent.setclass (friendslistactivity.this, recorderactivity.class); 
        Break 
        Default:break; 
      } startactivity (Intent); 
     
  ). Show (); /** * View more Operations/@Override public void Show (interaction interaction) {} @Override PU blic void Delete (interaction interaction) {//TODO auto-generated method stub} @Override public Vo  
      ID Onrefresh (pulltorefreshbase<listview> refreshview) {if (!isrefreshing) {isrefreshing = true; 
      MPage = 0; 
    Friendsapi.getfriendslist (Mcontext, mcallback); } protected Netcallback Mcallback = new Netcallback () {public void friendslist (Arraylist<interac 
      Tion> friends) {log.i ("Friends size>>>>", friends.size () + "-------------"); 
Madapter.setinteractions (Friends); 
      Mrefreshlistview.getloadinglayoutproxy (). Setlastupdatedlabel (NULL); 
      Mrefreshlistview.onrefreshcomplete (); Isrefreshing = false; 
    Dismissloading (); 
     
    }; 
    public void Start () {showloading (); 
     
    }; 
    public void failed (String message) {loadfailed (); 
  }; 
  }; 
    @Override public void Play (interaction interaction) {Intent mintent=new Intent (); 
    Mintent.setclass (Friendslistactivity.this, Recorderplayactivity.class); 
    Bundle data = new Bundle (); 
    Data.putstring ("path", Interaction.videopath); 
    Mintent.putextras (data); 
  StartActivity (mintent); 

 } 
}

layout file Friends_list.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=" match_parent "android:background=" @color/back Groud_color "> <include android:id=" @+id/list_title "android:layout_alignparenttop=" true "layout=" @layout/list_title "/> <com.yzl.xyb.friends.refresh.view.pulltorefreshlistview xmlns:app=" Http://schemas. Android.com/apk/res-auto "android:id=" @+id/friends_list "android:layout_width=" Match_parent "Android:layout"  
    _height= "Match_parent" android:layout_margin= "@dimen/padding_left" android:divider= "@android: Color/transparent" android:layout_below= "@+id/list_title" app:ptroverscroll= "false" app:ptrheadertextcolor= "#ff666666" a Pp:ptrheadertextappearance= "@android: Style/textappearance.small" app:ptrshowindicator= "false"/> <include LA yout= "@layout/loading"/> ≪/relativelayout> 
 

Adapter Interactionadapter Data fills the list of friends ' circles

public class Interactionadapter extends Baseadapter implements Onclicklistener {private arraylist<interaction> 
  Interactions 
  Private context Mcontext; 
  Private Finalbitmap mfinal; 
  Private Bitmapdisplayconfig config; 
  Private Bitmapdisplayconfig Imageconfig; 
  Private Postlistener listener; 
    Public Interactionadapter {mcontext = context; 
    Mfinal = Finalbitmap.create (Mcontext); 
    Bitmap Bitmap = Bitmapfactory.decoderesource (Mcontext.getresources (), R.drawable.user_avatar); 
    Config = new Bitmapdisplayconfig (); 
    Config.setanimationtype (BitmapDisplayConfig.AnimationType.fadeIn); 
    Config.setloadfailbitmap (bitmap); 
     
    Config.setloadfailbitmap (bitmap); 
    Bitmap = Bitmapfactory.decoderesource (Mcontext.getresources (), r.drawable.image_failed); 
    Imageconfig = new Bitmapdisplayconfig (); 
    Imageconfig.setanimationtype (BitmapDisplayConfig.AnimationType.fadeIn); 
    Imageconfig.setloadfailbitmap (bitmap); ImagecoNfig.setloadfailbitmap (bitmap); 
  public void Setlistener (Postlistener listener) {This.listener = listener; 
    public void Setinteractions (arraylist<interaction> interactions) {this.interactions = interactions; 
  Notifydatasetchanged ();  @Override public int GetCount () {//TODO auto-generated a stub return interactions = = null? 0 
  : Interactions.size (); @Override public Object getitem (int position) {//TODO auto-generated method stub return Interactions 
  . get (position); 
  @Override public long getitemid (int position) {//TODO auto-generated method stub return position; @Override public View getview (int position, View Convertview, ViewGroup parent) {//TODO auto-generated 
    Method stub Viewholder holder = null; 
      if (Convertview = = null) {Convertview = Layoutinflater.from (Mcontext). Inflate (R.layout.friend_list_item, NULL); Holder = new VIewholder (); 
      Holder.avatar = (Circleimageview) Convertview.findviewbyid (R.id.avatar); 
      Holder.content = (TextView) Convertview.findviewbyid (r.id.content); 
      Holder.title = (TextView) Convertview.findviewbyid (r.id.title); 
      Holder.subtitle = (TextView) Convertview.findviewbyid (r.id.subtitle); 
      Holder.image = Convertview.findviewbyid (r.id.image_layout); 
      HOLDER.IMAGE0 = (ImageView) Convertview.findviewbyid (R.ID.IMAGE0); 
      Holder.image1 = (ImageView) Convertview.findviewbyid (r.id.image1); 
      Holder.image2 = (ImageView) Convertview.findviewbyid (r.id.image2); 
      Holder.conments = (TextView) Convertview.findviewbyid (R.id.conment_count); 
      Holder.praises = (TextView) Convertview.findviewbyid (R.id.parise_count); 
      holder.praised = (ImageView) Convertview.findviewbyid (R.id.praise_icon); 
      Holder.more = (TextView) Convertview.findviewbyid (R.id.more); holder.viewlayout= (LinearLayout) Convertview.findviewbyid (r.id.view_layout);
      holder.surfaceview= (Surfaceview) Convertview.findviewbyid (R.id.surface_view_result); 
      holder.playbutton= (ImageButton) Convertview.findviewbyid (R.id.btn_play_result); 
      holder.audiolayout= (framelayout) Convertview.findviewbyid (r.id.audio_layout); 
    Convertview.settag (holder); 
    else {holder = (Viewholder) convertview.gettag (); 
    } Interaction interaction = Interactions.get (position); 
    if (Textutils.isempty (Interaction.avatar)) {Holder.avatar.setImageBitmap (Config.getloadfailbitmap ()); 
    else {mfinal.display (Holder.avatar, Interaction.avatar, config); 
    } holder.title.setText (Interaction.name); 
    Holder.subtitle.setText (Interaction.subtitle); 
     
    Holder.content.setText (interaction.content); 
    Holder.conments.setText (string.valueof (Interaction.commentcount)); 
     
    Holder.praises.setText (string.valueof (Interaction.praisecount)); int images = Interaction.images = null? 0:interactioN.images.size (); 
      if (Images > 0) {holder.image.setVisibility (view.visible); 
      Holder.audioLayout.setVisibility (View.gone); 
      Holder.image.setOnClickListener (this); 
      Holder.image.setTag (interaction); 
        if (images <= 1) {Mfinal.display (holder.image0, Interaction.images.get (0), imageconfig); 
        Holder.image1.setImageBitmap (NULL); 
      Holder.image2.setImageBitmap (NULL); 
        else if (Images <= 2) {Mfinal.display (holder.image0, Interaction.images.get (0), imageconfig); 
        Mfinal.display (Holder.image1, Interaction.images.get (1), imageconfig); 
      Holder.image2.setImageBitmap (NULL); 
        else {mfinal.display (holder.image0, Interaction.images.get (0), imageconfig); 
        Mfinal.display (Holder.image1, Interaction.images.get (1), imageconfig); 
         
      Mfinal.display (Holder.image2, Interaction.images.get (2), imageconfig); 
   } else if (interaction.videopath!=null) {holder.image.setVisibility (View.gone); 
        Holder.playButton.setBackgroundResource (r.drawable.play1pressed); 
        Holder.audioLayout.setVisibility (view.visible); 
        Holder.playButton.setTag (interaction); 
        Holder.playButton.setOnClickListener (this); 
        Holder.surfaceView.setTag (interaction); 
    Holder.surfaceView.setOnClickListener (this); 
    }else{holder.viewLayout.setVisibility (View.gone); 
    } holder.more.setTag (interaction); 
     
    Holder.more.setOnClickListener (this); 
  return convertview; 
    Private class Viewholder {Circleimageview avatar; 
    TextView title; 
    TextView subtitle; 
    TextView content; 
    View image; 
    ImageView Image0; 
    ImageView Image1; 
    ImageView Image2; 
    TextView conments; 
    TextView praises; 
    ImageView praised; 
    View Delete; 
    TextView more; 
    Surfaceview Surfaceview; 
    ImageButton PlayButton; 
  Framelayout audiolayout;  LinearLayout viewlayout; 
    @Override public void OnClick (View v) {int id = V.getid (); 
    if (id = = R.id.btn_play_result) {Interaction interaction = (interaction) V.gettag (); }else if (id = = R.id.surface_view_result) {if (This.listener!= null) {This.listener.play (interaction) 
      V.gettag ()); }}else if (id = = R.id.more) {if (This.listener!= null) {this.listener.show (interaction) V.gettag 
      ()); 
      } else if (id = = r.id.image_layout) {Intent Intent = new Intent (Mcontext, Mainactivity.class); 
      Bundle data = new Bundle (); 
      Interaction interaction = (interaction) V.gettag (); 
      Data.putstringarraylist ("Images", interaction.images); 
      Intent.putextras (data); 
    Mcontext.startactivity (Intent); 
    } public interface Postlistener {Void Show (interaction interaction); 
    void Delete (interaction interaction); 
  void Play (interaction interaction); } 
 


Multi-picture Selection implementation code

Multipleactivity

Package com.yzl.xyb.friends; 
Import Java.io.File; 
Import Java.io.FilenameFilter; 
Import java.util.ArrayList; 
Import Java.util.Arrays; 
Import Java.util.HashSet; 
 
Import java.util.List; 
Import android.app.Activity; 
Import Android.app.ProgressDialog; 
Import Android.content.ContentResolver; 
Import android.content.Intent; 
Import Android.database.Cursor; 
Import Android.net.Uri; 
Import Android.os.Bundle; 
Import android.os.Environment; 
Import Android.os.Handler; 
Import Android.provider.MediaStore; 
Import Android.util.DisplayMetrics; 
Import Android.util.Log; 
Import Android.view.LayoutInflater; 
Import Android.view.View; 
Import Android.view.View.OnClickListener; 
Import Android.view.ViewGroup.LayoutParams; 
Import Android.view.WindowManager; 
Import Android.widget.GridView; 
Import Android.widget.PopupWindow.OnDismissListener; 
Import Android.widget.RelativeLayout; 
Import Android.widget.TextView; 
 
Import Android.widget.Toast; Import Com.yzl.xyb.friends.adapter.MyAdaptEr 
Import Com.yzl.xyb.friends.adapter.MyAdapter.SetCountListener; 
Import Com.yzl.xyb.friends.picture.ListImageDirPopupWindow; 
Import com.yzl.xyb.friends.picture.ListImageDirPopupWindow.OnImageDirSelected; 
Import Com.yzl.xyb.friends.util.ImageFloder; /** * Select pictures from album * can choose more than 9 * get all albums * OK: Returns the path of the selected picture * @author HOU * * * */public class multipleactivity Exte 
  NDS activity implements Onimagedirselected, setcountlistener{private TextView selectcount; 
  Private TextView selectpicture; 
  Private TextView Mchoosedir; 
  Private ProgressDialog Mprogressdialog; 
  public static final int kitkat_less = 2; 
  /** * Store the number of pictures in the folder * * Private int mpicssize; 
  /** * The largest number of pictures folder * * Private File Mimgdir; 
  /** * All Pictures * * * private list<string> Mimgs; 
 
  Private arraylist<string> pictures; 
  Private GridView Mgirdview; 
  Private Myadapter Madapter; /** * Temporary auxiliary class, used to prevent multiple scans of the same folder * * Private hashset<string> mdirpaths = New Hashset<string> (); 
 
  /** * Scan to get all the Pictures folder * * Private list<imagefloder> mimagefloders = new arraylist<imagefloder> (); 
 
  Private Relativelayout mbottomly; 
 
  int totalcount = 0; 
 
  private int mscreenheight; 
 
  Private Listimagedirpopupwindow Mlistimagedirpopupwindow; Private Handler Mhandler = new Handler () {public void Handlemessage (Android.os.Message msg) {Mprogre 
      Ssdialog.dismiss (); 
      Bind the Data Data2view () for the view; 
    Initialize the POPUPWINDW INITLISTDIRPOPUPWINDW () of the display folder; 
   
 
  } 
  }; 
    @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); 
    Setcontentview (R.layout.picture_selector); 
    Getintent (). Getextras (); 
    Displaymetrics outmetrics = new Displaymetrics (); 
    Getwindowmanager (). Getdefaultdisplay (). Getmetrics (Outmetrics); 
 
    Mscreenheight = Outmetrics.heightpixels; 
    Initview (); 
    GetImages (); 
 
  Initevent (); } 
 
  /** * Initialize view */private void Initview () {Mgirdview = (GridView) Findviewbyid (R.id.id_gridview); 
    Mchoosedir = (TextView) Findviewbyid (R.id.id_choose_dir); 
SelectCount = (TextView) Findviewbyid (R.id.tv_select_count); 
    Allphotoalum = (TextView) Findviewbyid (R.id.tv_photoalum); 
    Selectpicture= (TextView) Findviewbyid (r.id.tv_sure); 
  mbottomly = (relativelayout) Findviewbyid (R.id.id_bottom_ly); private void Initevent () {/** * for the bottom of the layout set click event, Pop-up Popupwindow * * Mbottomly.setonclicklistene R (New Onclicklistener () {@Override public void OnClick (View v) {Mlistimagedirpopupwin 
        Dow. Setanimationstyle (R.STYLE.ANIM_POPUP_DIR); 
 
        Mlistimagedirpopupwindow.showasdropdown (mbottomly, 0, 0); 
        Set Background color darken windowmanager.layoutparams LP = GetWindow (). GetAttributes (); 
        Lp.alpha =. 3f; 
      GetWindow (). SetAttributes (LP); 
     } 
    });
    Selectpicture.setonclicklistener (New Onclicklistener () {@Override public void OnClick (View v) 
        {Pictures=madapter.getselectpath (); 
        LOG.I ("Selected picture 1>>>>>>", pictures.size () + "----------"); 
Intent intent=new Intent (); 
        Intent.setclass (Multipleactivity.this, Createpostactivity.class); 
        Bundle bundle=new Bundle (); 
        Bundle.putstringarraylist ("PICTURES", PICTURES); 
Intent.putextras (bundle); 
        Startactivityforresult (Intent, kitkat_less);  
        Setresult (kitkat_less, intent); 
      Finish (); 
  } 
    }); }/** * For view binding data/private void Data2view () {if (Mimgdir = null) {Toast.maketext ( 
      Getapplicationcontext (), "wipe, one picture not scanned", Toast.length_short). Show (); 
    Return 
    } Mimgs = Arrays.aslist (Mimgdir.list ()); /** * You can see the path of the folder and the path of the picture saved separately, greatly reducing the memory consumption;/Madapter = new Myadapter (getapplicationcOntext (), Mimgs, R.layout.grid_item, Mimgdir.getabsolutepath ()); 
    Madapter.setcountlistener (this); 
Mgirdview.setadapter (Madapter); 
  Allpicturecount.settext ("Altogether" +totalcount + "Zhang"); 
 
  }; /** * Initialize the display folder POPUPWINDW/private void Initlistdirpopupwindw () {Mlistimagedirpopupwindow = new List Imagedirpopupwindow (layoutparams.match_parent, (int) (Mscreenheight * 1), mimagefloders, Layoutinflater 
 
    . from (Getapplicationcontext ()). Inflate (R.layout.list_dir, null)); Mlistimagedirpopupwindow.setondismisslistener (New Ondismisslistener () {@Override public void Ondismi 
        SS () {//Set background color dimming windowmanager.layoutparams LP = GetWindow (). GetAttributes (); 
        Lp.alpha = 1.0f; 
      GetWindow (). SetAttributes (LP); 
    } 
    }); 
  Sets the callback mlistimagedirpopupwindow.setonimagedirselected for the Select folder (this); /** * Using ContentProvider to scan pictures in mobile phones, this method is running in child threads to complete the scan of the picture, the mostFinally get the most JPG folder * * private void GetImages () {if (! Environment.getexternalstoragestate (). Equals (environment.media_mounted)) {Toast.maketext (this, "temporarily no outside 
      Department store ", Toast.length_short). Show (); 
    Return 
 
    ///Show progress bar Mprogressdialog = Progressdialog.show (this, null, "Loading ..."); 
 
        New Thread (New Runnable () {@Override public void run () {String firstimage = null; 
        Uri Mimageuri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; 
 
        Contentresolver mcontentresolver = multipleactivity.this. Getcontentresolver (); Query only JPEG and png pictures Cursor mcursor = mcontentresolver.query (Mimageuri, NULL, MEDIASTORE.IMAGES.MEDIA.M Ime_type + "=?  
            or "+ MediaStore.Images.Media.MIME_TYPE +" =? ", new string[] {" Image/jpeg "," Image/png "}, 
 
        MediaStore.Images.Media.DATE_MODIFIED); LOG.E ("TAG", Mcursor.getcount () + ""); 
        while (Mcursor.movetonext ()) {//Get the path of the picture String path = mcursor.getstring (mcursor 
 
          . Getcolumnindex (MediaStore.Images.Media.DATA)); 
          LOG.E ("TAG", Path); 
          Get the first picture of the path if (firstimage = null) firstimage = path; 
          Gets the parent path name of the picture, file Parentfile = new file (path). Getparentfile (); 
          if (Parentfile = = null) continue; 
          String Dirpath = Parentfile.getabsolutepath (); 
          Imagefloder imagefloder = null; Use a hashset to prevent multiple scans of the same folder (without this judgment, the picture is more or less scary ~ ~) if (Mdirpaths.contains (Dirpath)) {Co 
          Ntinue; 
            else {mdirpaths.add (dirpath); 
            Initialize Imagefloder Imagefloder = new Imagefloder (); 
            Imagefloder.setdir (Dirpath); 
          Imagefloder.setfirstimagepath (path); int picsize = parentfile.list (New FilenaMefilter () {@Override public boolean accept (File dir, String filename) {if (Filename.endswith (". jpg") | | filename.endswith (". png") | | filen 
              Ame.endswith (". jpeg")) return true; 
            return false; 
          }). length; 
 
          TotalCount + = Picsize; 
          Imagefloder.setcount (picsize); 
 
          Mimagefloders.add (Imagefloder); 
            if (Picsize > mpicssize) {mpicssize = picsize; 
          Mimgdir = Parentfile; 
 
        } mcursor.close (); 
 
        The scan completes, the auxiliary HashSet also can release the memory mdirpaths = NULL; 
 
      Notify handler scan picture complete mhandler.sendemptymessage (0x110); 
 
  }). Start (); 
    @Override public void selected (Imagefloder floder) {mimgdir = new File (Floder.getdir ()); Mimgs = Arrays.aslist (mimgdir.list (New Filenamefilter () {@Override public boolean accept (File dir, String filename) {if filename.endsw ITH (". jpg") | | Filename.endswith (". png") | | 
        Filename.endswith (". jpeg")) return true; 
      return false; 
    } 
    })); 
        /** * You can see the path of the folder and the path of the picture saved separately, greatly reducing the memory consumption; */madapter = new Myadapter (Getapplicationcontext (), Mimgs, 
    R.layout.grid_item, Mimgdir.getabsolutepath ()); 
    Madapter.setcountlistener (this); 
Mgirdview.setadapter (Madapter); 
Madapter.notifydatasetchanged (); 
    Mimagecount.settext (Floder.getcount () + "Zhang"); 
    Mchoosedir.settext (Floder.getname ()); 
    Selectcount.settext ("/9"); 
 
  Mlistimagedirpopupwindow.dismiss (); 
  @Override public void Docount (int a) {Selectcount.settext (A + "/9"); 
 } 
   
 
}


Recording and previewing of video

Package com.yzl.xyb.friends; 
Import Android.annotation.SuppressLint; 
Import android.app.Activity; 
Import android.content.Intent; 
Import Android.os.Bundle; 
Import Android.os.Handler; 
Import Android.os.Message; 
Import Android.util.Log; 
Import android.view.MotionEvent; 
Import Android.view.View; 
Import Android.view.View.OnTouchListener; 
Import Android.widget.Button; 
 
Import Android.widget.Toast; 
Import Com.yzl.xyb.friends.view.MovieRecorderView; 
Import Com.yzl.xyb.friends.view.MovieRecorderView.OnRecordFinishListener; /** * Recording video * @author HOU * */public class Recorderactivity extends activity {private Movierecorderview MRe 
  Corderview; 
  Private Button mshootbtn; 
  Private Boolean isfinish = true; 
  Private String userId = ""; @Override protected void OnCreate (Bundle savedinstancestate) {//TODO auto-generated method stub Super.oncre 
    Ate (savedinstancestate); 
Setcontentview (r.layout.record_activity); Userid=getintent (). GetparcElableextra ("UserId"); 
    Mrecorderview = (Movierecorderview) Findviewbyid (R.id.movierecorderview); 
 
    MSHOOTBTN = (Button) Findviewbyid (R.id.shoot_button);  Mshootbtn.setontouchlistener (New Ontouchlistener () {@Override public boolean ontouch (View V, motionevent Event) {if (event.getaction () = = Motionevent.action_down) {Mrecorderview.record (new ONRECORDFINISHL Istener () {@Override public void Onrecordfinish () {log.i ("motionevent>> 
              > "," Action_down "); 
            Handler.sendemptymessage (1); 
        } 
          }); 
          else if (event.getaction () = = motionevent.action_up) {log.i ("motionevent>>>", "action_up"); 
          if (Mrecorderview.gettimecount () > 1) handler.sendemptymessage (1); 
            else {if (mrecorderview.getmvecordfile ()!= null) mrecorderview.getmvecordfile (). Delete (); MrecorderView.stop (); 
          Toast.maketext (Recorderactivity.this, "Time is too short, recording failed", Toast.length_short). Show ();  
      } return true; 
  } 
    }); 
    @Override public void Onresume () {super.onresume (); 
  Isfinish = true; 
    @Override public void Onsaveinstancestate (Bundle outstate) {super.onsaveinstancestate (outstate); 
    Isfinish = false; 
  Mrecorderview.stop (); 
  @Override public void OnPause () {super.onpause (); 
  @Override public void OnDestroy () {Super.ondestroy (); @SuppressLint ("Handlerleak") private Handler Handler = new Handler () {@Override public void Handlemes 
      Sage (msg) {finishactivity (); 
    LOG.I ("isfinish>>>", isfinish+ ""); 
 
  } 
  }; 
       
      private void Finishactivity () {if (isfinish) {mrecorderview.stop (); 
      Intent Intent = new Intent (recorderactivity.this, Topicactivity.class); Bundle MbundlE = new Bundle ();   
      Mbundle.putstring ("Path", Mrecorderview.getmvecordfile (). toString ()); 
      Mbundle.putstring ("UserId", userId);   
      Intent.putextras (Mbundle);  
    StartActivity (Intent); 
    } public interface Onshootcompletionlistener {public void onshootsuccess (String path, int second); 
  public void Onshootfailure (); 

 } 
}

preview of video

Package com.yzl.xyb.friends; 
Import android.app.Activity; 
Import Android.media.AudioManager; 
Import Android.media.MediaPlayer; 
Import Android.os.Bundle; 
Import Android.view.SurfaceHolder; 
Import Android.view.SurfaceView; 
Import Android.view.View; 
Import Android.view.View.OnClickListener; 
Import Android.widget.ImageButton; 
 
Import Android.widget.ImageView; public class Recorderplayactivity extends activity implements Surfaceholder.callback, Onclicklistener {private Image 
  View Ivback; 
  Private ImageButton Btnplay; 
  Private Surfaceview Surfaceview; 
  Private Surfaceholder Surfaceholder; 
  Private String Path=null; 
  Private MediaPlayer player; 
   
  Private Boolean play=false; @SuppressWarnings ("deprecation") @Override protected void OnCreate (Bundle savedinstancestate) {//TODO Auto-ge 
    nerated method Stub super.oncreate (savedinstancestate); 
    Setcontentview (R.layout.recorder_play); 
    ivback= (ImageView) Findviewbyid (r.id.iv_back); BTnplay= (ImageButton) Findviewbyid (R.id.ib_play); 
    surfaceview= (Surfaceview) Findviewbyid (R.id.play_view); 
    Btnplay.setbackground (Getresources (). getdrawable (r.drawable.play1pressed)); 
    Path=this.getintent (). Getstringextra ("path"); 
    System.out.println ("Surface created>>>> path=" +path); 
    Surfaceholder=surfaceview.getholder (); 
    Surfaceholder.addcallback (this); 
    Surfaceholder.setfixedsize (320, 220); 
    Surfaceholder.settype (surfaceholder.surface_type_push_buffers); 
    System.out.println ("OnCreate--------------"); 
    Ivback.setonclicklistener (this); 
    Btnplay.setonclicklistener (this); 
  Surfaceview.setonclicklistener (this); 
    @Override public void surfacecreated (Surfaceholder holder) {player=new MediaPlayer (); 
    Player.setaudiostreamtype (Audiomanager.stream_music); 
    Player.setdisplay (Surfaceholder); 
      try {System.out.println ("surface created>>>> path=" +path); Player.setdatasource (PATH); 
    Player.prepare (); 
    catch (Exception e) {e.printstacktrace (); 
    @Override public void surfacechanged (surfaceholder holder, int format, int width, int height) { 
    TODO auto-generated Method stub} @Override public void surfacedestroyed (Surfaceholder holder) { TODO auto-generated Method Stub} @Override the public void OnClick (View v) {switch (V.getid) ( 
      ) {case r.id.iv_back:this.finish (); 
    Break 
      Case R.id.ib_play:player.start (); 
      Btnplay.setvisibility (View.gone); 
    Break 
      Case R.id.play_view:player.pause (); 
      /*if (play) {Player.start (); 
      }else {player.pause (); 
      }*/btnplay.setvisibility (view.visible); 
 
    Break 
    Default:break; 
    } @Override protected void OnDestroy () {//TODO auto-generated Method Stub Super.ondestroy (); if (player.isPlaying ()) {player.stop (); 
  } player.release (); 
 } 
}

Have a friend circle of their own is not very open new, can and good friends anytime and anywhere to share, is not very happy!

This is the entire content of this article, I hope to learn more about Android software programming help.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.