基于安卓平台的程序开发--杨婷_第1页
基于安卓平台的程序开发--杨婷_第2页
基于安卓平台的程序开发--杨婷_第3页
基于安卓平台的程序开发--杨婷_第4页
基于安卓平台的程序开发--杨婷_第5页
已阅读5页,还剩22页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、安卓平台的程序开发学校: 班级: 姓名: 学号: 一.实训技术简介Android应用程序是在JAVA下开发的。Android自身不是一个语言,但是是一个运行应用程序的环境。 1.eclipse Eclipse是一个开放源代码的、基于java的可扩展开发平台,就其本身而言,它只是一个框架和服务,用于通过插件组件构建开发环境。eclipse附带了一个标准的插件集,包括java开发工具。一旦Eclipse安装开始,你会被提醒来创建一个缺省的工作空间,或者文件夹。和其他大多数开发环境一样,项目被创建,并且保存到这个工作空间内。2.JDKJDK是一个写java的applet和应用程序的程序开发环境。它由

2、一个处于操作系统层之上的运行环境还有开发者编译,调试和运行用java语言写的applet和应用程序所需的工具组成。JDK包含的基本组件包括:Javac-编译器,将源代码转成字节码Jar-打包工具,将相关的类文件打包成一个文件Javadoc-文档生成器,从源码注释中提取文档Jdb-debugger,查错工具JDK中还包括各种例子程序,用以展示java API中的各部分。3.android-sdkSDK:Android SDK下载后会是一个简单的ZIP文件压缩包。Android SDK的主体是一些文件,连续性的文档,可编程的API,工具,例子和其它。AndroidSDK和其它的SDK相比没有任何的

3、不同,它包含了所有的创建运行在特有的Android平台上应用程序所需的Java代码库。SDK还包括帮助文件,文档和Android模拟器,大量的开发和调试工具。被软件开发工程师用于为特定的软件包、软件框架、硬件平台、操作系统等建立应用软件的开发工具的集合。Android SDK指的既是android专属的软件开发工具包。二实训项目简介1.编写电话应用 2.编写短信应用 3.编写音乐播放器应用 4.编写纸牌游戏 5.编写推箱子游戏 6.编写公交查询应用三实训项目具体说明(包括项目实现步骤和项目截图,可以包括部分核心代码) 1.编写电话应用package com.example.yt_app;imp

4、ort android.app.Activity;import android.content.Intent;import .Uri;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.EditText;import android.widget.Toast;/* * author T * */public class CallActivity extends Ac

5、tivity EditText telNum; Overrideprotected void onCreate(Bundle savedInstanceState) / TODO Auto-generated method stubsuper.onCreate(savedInstanceState);setContentView(R.layout.call);telNum=(EditText)findViewById(R.id.mobileNum);Button button=(Button)findViewById(R.id.cbutton);button.setOnClickListene

6、r(new ButtonClick();public class ButtonClick implements OnClickListenerOverridepublic void onClick(View arg0) / TODO Auto-generated method stubString mobileNum=telNum.getText().toString();if(mobileNum=null | mobileNum.equals("")Toast.makeText(CallActivity.this, R.string.text, Toast.LENGTH_

7、LONG).show();elseIntent intent=new Intent(Intent.ACTION_CALL,Uri.parse("tel:"+mobileNum); startActivity(intent); 2.编写短信应用 package com.example.yt_app;import java.util.List;import android.app.Activity;import android.os.Bundle;import android.telephony.SmsManager;import android.view.View;impor

8、t android.view.View.OnClickListener;import android.widget.Button;import android.widget.EditText;import android.widget.Toast;public class SmsActivity extends Activity private EditText telNum;private EditText smsContext;/*(non-Javadoc) * see android.app.Activity#onCreate(android.os.Bundle) */Overridep

9、rotected void onCreate(Bundle SavedIstanceState)super.onCreate (SavedIstanceState);setContentView(R.layout.message);telNum=(EditText)findViewById(R.id.phoneNumber);smsContext=(EditText)findViewById(R.id.message);Button button=(Button)findViewById(R.id.msButton);public class ButtonClick implements On

10、ClickListenerOverridepublic void onClick(View arg0) String mobile=telNum.getText().toString();String sms=smsContext.getText().toString();if(mobile=null|mobile.equals("")Toast.makeText(SmsActivity.this,"手机号码不能为空",Toast.LENGTH_LONG);else if(sms=null|sms.equals("")Toast.ma

11、keText(SmsActivity.this,"短信内容不能为空",Toast.LENGTH_LONG);elseSmsManager smsManager=SmsManager.getDefault();if(sms.length()>70)List<String> list=smsManager.divideMessage(sms);for(String s:list)smsManager.sendTextMessage(mobile,null,s,null,null);elsesmsManager.sendTextMessage(mobile,nu

12、ll,sms,null,null);Toast.makeText(SmsActivity.this,"短信已发出",Toast.LENGTH_LONG).show(); 3.编写音乐播放器应用 package com.example.yt_app;import java.io.File;import java.io.FilenameFilter;import java.io.IOException;import java.util.ArrayList;import java.util.List;import android.app.Activity;import andro

13、id.graphics.Color;import android.media.MediaPlayer;import android.media.MediaPlayer.OnCompletionListener;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.ImageButton;import android.widget.TableLayout;import android.widget.TableRow;impor

14、t android.widget.TextView;public class MusicActivity extends Activity private ImageButton play_pause; private ImageButton play_stop; private ImageButton play_next; private ImageButton play_prev; private TableLayout tl; private static final String MUSIC_BASE_PATH="/sdcard/" private List<

15、String>music_list=new ArrayList<String>(); private boolean pause=false; private MediaPlayer mp; private int currentIndex=0; Overrideprotected void onCreate(Bundle savedInstanceState) / TODO Auto-generated method stubsuper.onCreate(savedInstanceState);setContentView(R.layout.music);play_paus

16、e=(ImageButton)findViewById(R.id.play_pause);play_stop=(ImageButton)findViewById(R.id.play_stop);play_next=(ImageButton)findViewById(R.id.play_next);play_prev=(ImageButton)findViewById(R.id.play_prev);mp=new MediaPlayer();tl=(TableLayout)findViewById(R.id.song_list);loadSong();/* * 下一首 * param path

17、*/public void nextplay()play_pause.setImageResource(R.drawable.player_next_light);if(+currentIndex>=music_list.size()currentIndex=0;play(MUSIC_BASE_PATH+music_list.get(currentIndex);/* * 上一首 * param path */public void prevplay()play_pause.setImageResource(R.drawable.player_prev_light);if(-current

18、Index<0)currentIndex=music_list.size()-1;play(MUSIC_BASE_PATH+music_list.get(currentIndex);/* * 播放当前音乐 * param path */public void play(String path)play_pause.setImageResource(R.drawable.player_pause_light);mp.reset();trymp.setDataSource(path);mp.prepare();mp.start();mp.setOnCompletionListener(new

19、 OnCompletionListener() Overridepublic void onCompletion(MediaPlayer arg0) / TODO Auto-generated method stub); catch (SecurityException e) / TODO Auto-generated catch blocke.printStackTrace(); catch (IllegalStateException e) / TODO Auto-generated catch blocke.printStackTrace(); catch (IOException e)

20、 / TODO Auto-generated catch blocke.printStackTrace();public void currentMusic()int count=tl.getChildCount();for(int i=1;i<count;i+)tl.getChildAt(i).setBackgroundColor(Color.TRANSPARENT);TableRow tr=(TableRow)tl.getChildAt(currentIndex+1);if(tr!=null)tr.setBackgroundColor(Color.RED);public void l

21、oadSong()File file=new File(MUSIC_BASE_PATH);File f=file.listFiles(new FilenameFilter() Overridepublic boolean accept(File arg0, String arg1) / TODO Auto-generated method stubreturn arg1.endsWith(".mp3"););if(f.length>0)for(int i=0;i<f.length;i+)music_list.add(fi.getName();TableRow t

22、r=new TableRow(this); TextView tv1=new TextView(this);tv1.setText(""+(i+1);tr.addView(tv1,0);TextView tv2=new TextView(this);tv2.setText(fi.getName();tr.addView(tv2,1);TextView tv3=new TextView(this);tv3.setText(fi.length()/(1024*1024)+"");tr.addView(tv3,2);tl.addView(tr);play_pa

23、use.setOnClickListener(new OnClickListener() Overridepublic void onClick(View arg0) / TODO Auto-generated method stubif (mp.isPlaying() play_pause.setImageResource(R.drawable.player_pause_light);mp.pause();pause=true;elseif(pause) mp.start();elseplay_pause.setImageResource(R.drawable.player_play_lig

24、ht);if(+currentIndex>=music_list.size() currentIndex=0;play(MUSIC_BASE_PATH+music_list.get(currentIndex););package com.example.yt_app;import java.io.File;import java.io.FilenameFilter;import java.io.IOException;import java.util.ArrayList;import java.util.List;import android.app.Activity;import an

25、droid.graphics.Color;import android.media.MediaPlayer;import android.media.MediaPlayer.OnCompletionListener;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.ImageButton;import android.widget.TableLayout;import android.widget.TableRow;im

26、port android.widget.TextView;public class MusicActivity extends Activity private ImageButton play_pause; private ImageButton play_stop; private ImageButton play_next; private ImageButton play_prev; private TableLayout tl; private static final String MUSIC_BASE_PATH="/sdcard/" private List&

27、lt;String>music_list=new ArrayList<String>(); private boolean pause=false; private MediaPlayer mp; private int currentIndex=0; Overrideprotected void onCreate(Bundle savedInstanceState) / TODO Auto-generated method stubsuper.onCreate(savedInstanceState);setContentView(R.layout.music);play_p

28、ause=(ImageButton)findViewById(R.id.play_pause);play_stop=(ImageButton)findViewById(R.id.play_stop);play_next=(ImageButton)findViewById(R.id.play_next);play_prev=(ImageButton)findViewById(R.id.play_prev);mp=new MediaPlayer();tl=(TableLayout)findViewById(R.id.song_list);loadSong();/* * 下一首 * param pa

29、th */public void nextplay()play_pause.setImageResource(R.drawable.player_next_light);if(+currentIndex>=music_list.size()currentIndex=0;play(MUSIC_BASE_PATH+music_list.get(currentIndex);/* * 上一首 * param path */public void prevplay()play_pause.setImageResource(R.drawable.player_prev_light);if(-curr

30、entIndex<0)currentIndex=music_list.size()-1;play(MUSIC_BASE_PATH+music_list.get(currentIndex);/* * 播放当前音乐 * param path */public void play(String path)play_pause.setImageResource(R.drawable.player_pause_light);mp.reset();trymp.setDataSource(path);mp.prepare();mp.start();mp.setOnCompletionListener(

31、new OnCompletionListener() Overridepublic void onCompletion(MediaPlayer arg0) / TODO Auto-generated method stub); catch (SecurityException e) / TODO Auto-generated catch blocke.printStackTrace(); catch (IllegalStateException e) / TODO Auto-generated catch blocke.printStackTrace(); catch (IOException

32、 e) / TODO Auto-generated catch blocke.printStackTrace();public void currentMusic()int count=tl.getChildCount();for(int i=1;i<count;i+)tl.getChildAt(i).setBackgroundColor(Color.TRANSPARENT);TableRow tr=(TableRow)tl.getChildAt(currentIndex+1);if(tr!=null)tr.setBackgroundColor(Color.RED);public voi

33、d loadSong()File file=new File(MUSIC_BASE_PATH);File f=file.listFiles(new FilenameFilter() Overridepublic boolean accept(File arg0, String arg1) / TODO Auto-generated method stubreturn arg1.endsWith(".mp3"););if(f.length>0)for(int i=0;i<f.length;i+)music_list.add(fi.getName();TableRo

34、w tr=new TableRow(this); TextView tv1=new TextView(this);tv1.setText(""+(i+1);tr.addView(tv1,0);TextView tv2=new TextView(this);tv2.setText(fi.getName();tr.addView(tv2,1);TextView tv3=new TextView(this);tv3.setText(fi.length()/(1024*1024)+"");tr.addView(tv3,2);tl.addView(tr);play

35、_pause.setOnClickListener(new OnClickListener() Overridepublic void onClick(View arg0) / TODO Auto-generated method stubif (mp.isPlaying() play_pause.setImageResource(R.drawable.player_pause_light);mp.pause();pause=true;elseif(pause) mp.start();elseplay_pause.setImageResource(R.drawable.player_play_

36、light);if(+currentIndex>=music_list.size() currentIndex=0;play(MUSIC_BASE_PATH+music_list.get(currentIndex);); 4.编写纸牌游戏package com.example.yt_app;import java.util.Arrays;import java.util.Collections;import java.util.List;import android.app.Activity;import android.app.AlertDialog;import android.co

37、ntent.DialogInterface;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.ImageView;import com.example.yt_app.R;public class PokerActivity extends Activity private ImageView pk1;private ImageView pk2;private Im

38、ageView pk3;private ImageView pk4;private Integer poker=R.drawable.poker_kk,R.drawable.poker_k,R.drawable.poker_q,R.drawable.poker_a;private int key=R.drawable.poker_k;private boolean flag=false;Overrideprotected void onCreate(Bundle savedInstanceState) / TODO Auto-generated method stubsuper.onCreat

39、e(savedInstanceState);setContentView(R.layout.poker);pk1=(ImageView)findViewById(R.id.pk1);pk2=(ImageView)findViewById(R.id.pk2);pk3=(ImageView)findViewById(R.id.pk3);pk4=(ImageView)findViewById(R.id.pk4);Button button=(Button)findViewById(R.id.pokerButton);button.setOnClickListener(new OnClickListe

40、ner() Overridepublic void onClick(View arg0) / TODO Auto-generated method stubshuffpoker(););pk1.setOnClickListener(new ImageViewClick();pk2.setOnClickListener(new ImageViewClick();pk3.setOnClickListener(new ImageViewClick();pk4.setOnClickListener(new ImageViewClick();public void shuffpoker()List<

41、;Integer> list=Arrays.asList(poker);Collections.shuffle(list);poker=(Integer)list.toArray();pk1.setAlpha(255);pk2.setAlpha(255);pk3.setAlpha(255);pk4.setAlpha(255);flag=false;pk1.setImageResource(R.drawable.poker_bg);pk2.setImageResource(R.drawable.poker_bg);pk3.setImageResource(R.drawable.poker_

42、bg);pk4.setImageResource(R.drawable.poker_bg);public class ImageViewClick implements OnClickListenerOverridepublic void onClick(View arg0) / TODO Auto-generated method stubif(!flag)pk1.setImageResource(poker0);pk2.setImageResource(poker1);pk3.setImageResource(poker2);pk4.setImageResource(poker3);fla

43、g=true;pk1.setAlpha(100);pk2.setAlpha(100);pk3.setAlpha(100);pk4.setAlpha(100);int temp=0;switch(arg0.getId()case R.id.pk1:temp=0;pk1.setAlpha(255);break;case R.id.pk2:temp=0;pk2.setAlpha(255);break;case R.id.pk3:temp=0;pk3.setAlpha(255);break;case R.id.pk4:temp=0;pk4.setAlpha(255);break;if(key=poke

44、rtemp)dialog("对了","聪明");elsedialog("错了","笨蛋"); public void dialog(String title,String msg)new AlertDialog.Builder(PokerActivity.this).setIcon(R.drawable.title_icon).setTitle(title).setMessage(msg).setPositiveButton("确定", new DialogInterface.OnClickLi

45、stener() Overridepublic void onClick(DialogInterface arg0, int arg1) / TODO Auto-generated method stub/关闭对话框arg0.dismiss();/重新洗牌shuffpoker();).setNegativeButton("取消", new DialogInterface.OnClickListener() Overridepublic void onClick(DialogInterface arg0, int arg1) / TODO Auto-generated met

46、hod stub/关闭对话框arg0.dismiss();/重新洗牌shuffpoker();).show(); 5.编写推箱子游戏6. 编写城市查询。7.编写公交路线查询。package com.example.yt_app;import android.app.Activity;import android.database.Cursor;import android.database.sqlite.SQLiteDatabase;import android.os.Bundle;import android.text.method.ScrollingMovementMethod;impor

47、t android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.EditText;import android.widget.TextView;import android.widget.Toast;import com.example.mb.ImportDBFile;import com.example.model.Bus;public class BusActivity extends Activityprivate SQLiteD

48、atabase sqliteDatabase;private ImportDBFile importDBFile;protected void onCreate(Bundle savedInstanceState) importDBFile=new ImportDBFile(this);importDBFile.openDatabase();importDBFile.close();super.onCreate(savedInstanceState);setContentView(R.layout.bus);final EditText line=(EditText)findViewById(

49、R.id.line);final EditText stationName=(EditText)findViewById(R.id.stationName);Button button=(Button)findViewById(R.id.busButton);final TextView result=(TextView)findViewById(R.id.result);result.setMovementMethod(ScrollingMovementMethod.getInstance();sqliteDatabase=SQLiteDatabase.openOrCreateDatabas

50、e(importDBFile.PATH+"/"+importDBFile.db,null);line.setOnClickListener(new OnClickListener() public void onClick(View argO) stationName.setText(""););stationName.setOnClickListener(new OnClickListener()public void onClick(View argO)String lineNum=line.getText().toString();String station=stationName.getText().toString(); Bus bus=new Bus();StringBuffer buffer=new StringBuffer();Cursor cursor=null;if(lineNum!=null&&!lineNum.equals("")cursor=sqliteDatabase.rawQuery("select busw,shijian,kind,piao fro

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论