Primary arithmetic app stage three sprint-first day

Source: Internet
Author: User

Team members: Chen Shuyun, Yang Jiane, Chen Xi

Team selection: Primary arithmetic App

Third Sprint stage time: 12.12~12.22

This release is the music playback function, can play music according to user needs while doing the problem, but also has a pause to play the music function, enhance the practicality of the app

Mainactivity.java:

Package Com.example.calculator;import Android.os.bundle;import Android.app.activity;import android.content.Intent; Import Android.util.log;import android.view.menu;import Android.view.view;import Android.view.View.OnClickListener Import Android.widget.button;public class Mainactivity extends Activity {private button Xunlian,choice;private button Playmusic; @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);        Setcontentview (R.layout.activity_main); Findview (); Playmusic.setonclicklistener (Startlis); xunlian= (Button) Findviewbyid (R.id.button1); LOG.I ("Playmusic", "Playmusic OnCreate is run"), choice= (Button) Findviewbyid (r.id.button2); Xunlian.setonclicklistener (New Onclicklistener () {@Overridepublic void OnClick (View arg0) {//TODO auto-generated method stubintent intent=new Inten T (); Intent.setclass (Mainactivity.this, Calculatorset.class); startactivity (intent); MainActivity.this.finish ();}}); Choice.setonclicklistener (New Onclicklistener () {@OverridepuBlic void OnClick (View arg0) {//TODO auto-generated method Stubintent intent=new Intent (); Intent.setclass ( Mainactivity.this, Choiceset.class); startactivity (intent); MainActivity.this.finish ();}});}    @Override protected void OnStart () {//TODO auto-generated Method Stub Super.onstart ();    LOG.I ("Playmusic", "Playmusic OnStart is run");    } @Override protected void Onrestart () {//TODO auto-generated Method Stub Super.onrestart ();    LOG.I ("Playmusic", "Playmusic Onrestart is run");    } @Override protected void Onresume () {//TODO auto-generated Method Stub super.onresume ();    LOG.I ("Playmusic", "Playmusic Onresume is run");    } @Override protected void OnStop () {//TODO auto-generated Method Stub super.onstop ();    LOG.I ("Playmusic", "Playmusic OnStop is run");    } @Override protected void OnPause () {//TODO auto-generated Method Stub super.onpause ();    LOG.I ("Playmusic", "Playmusic OnPause is run");   } @Override protected void OnDestroy () {//TODO auto-generated Method Stub Super.ondestroy ();    LOG.I ("Playmusic", "Playmusic OnDestroy is run");            } Private Onclicklistener Startlis=new Onclicklistener () {@Override public void OnClick (View v) {              TODO auto-generated Method Stub StartService (new Intent (Mainactivity.this, Musicservice.class)); Start Service}};p rivate void Findview () {//TODO auto-generated method stubplaymusic= (Button) findviewbyi D (r.id.playmusic);} @Overridepublic boolean Oncreateoptionsmenu (Menu menu) {//Inflate the menu; This adds items to the action bar if it is PR Esent.getmenuinflater (). Inflate (R.menu.main, menu); return true;}}

Activity_main.xml:

<relativelayout xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:tools= "http// Schemas.android.com/tools "android:layout_width=" match_parent "android:layout_height=" Match_parent "android:backg round= "@drawable/sea" android:paddingbottom= "@dimen/activity_vertical_margin" android:paddingleft= "@dimen/ Activity_horizontal_margin "android:paddingright=" @dimen/activity_horizontal_margin "android:paddingtop=" @dimen/ Activity_vertical_margin "tools:context=". Mainactivity "> <textview android:id=" @+id/textview2 "android:layout_width=" Wrap_content "an droid:layout_height= "Wrap_content" android:layout_alignparenttop= "true" Android:layout_centerhorizontal= "Tru E "android:layout_margintop=" 122DP "android:text=" @string/hello_world "android:textsize=" @dimen/btnte Xtsize "/> <button android:id=" @+id/button1 "android:layout_width=" Wrap_content "Android:lay Out_height= "WRAp_content "android:layout_alignleft=" @+id/textview2 "android:layout_alignright=" @+id/textView2 "Android oid:layout_below= "@+id/textview2" android:layout_margintop= "56DP" android:text= "into the general training system" Android:tex Tsize= "@dimen/btntextsizes"/> <button android:id= "@+id/button2" style= "? Android:attr/buttonstylesm All "android:layout_width=" Wrap_content "android:layout_height=" Wrap_content "Android:layout_alignlef t= "@+id/button1" android:layout_alignright= "@+id/button1" android:layout_below= "@+id/button1" Android         : layout_margintop= "23DP" android:text= "Enter the selection training system" android:textsize= "@dimen/btntextsizes"/> <button         Android:id= "@+id/button3" style= "Android:attr/buttonstylesmall" android:layout_width= "Wrap_content" android:layout_height= "Wrap_content" android:layout_alignleft= "@+id/button2" Android:layout_alignrig       ht= "@+id/button2" android:layout_below= "@+id/button2" android:layout_margintop= "21DP" android:text= "into the exam topic system" Android: Textsize= "@dimen/btntextsizes"/> <button android:id= "@+id/playmusic" android:layout_width= "Wrap_co Ntent "android:layout_height=" Wrap_content "android:layout_alignparenttop=" true "android:background="        @drawable/music "/> <button android:id=" @+id/stopmusic "android:layout_width=" Wrap_content " android:layout_height= "Wrap_content" android:layout_alignbottom= "@+id/playmusic" android:layout_toRightOf= "@ +id/playmusic "android:background=" @drawable/button_blue_pause "/></relativelayout>

Musicservice.java:

Package Com.example.calculator;import Android.app.service;import Android.content.intent;import Android.media.mediaplayer;import Android.os.ibinder;import Android.util.log;public class MusicService extends Service{private MediaPlayer MP;    Private String tag= "Main";        @Overridepublic ibinder onbind (Intent arg0) {//TODO auto-generated method Stubreturn null;}    @Override public    void OnCreate () {        super.oncreate ();        Mp=mediaplayer.create (this,r.raw.big);        LOG.I (TAG, "Musicservice OnCreate is run");    }    @Override public    int Onstartcommand (Intent Intent, int flags, int startid) {    //TODO auto-generated method stub
   mp.start ();     LOG.I (TAG, "Musicservice Onstartcommand is run");     Return Super.onstartcommand (Intent, flags, Startid);        }    @Override public    void OnDestroy () {        Super.ondestroy ();        Mp.stop ();        LOG.I (TAG, "Musicservice OnDestroy is Running");}    }

Operation Result:

Primary arithmetic app stage three sprint-first day

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.