android实训报告

时间:2024.3.24

南  京  师  范  大  学  泰  州  学  院

信   息   工   程   学   院

  Android实 训 报 告

题  目:          Android GPS系统           

学    号:        09090103              

姓    名:         冯超洁               

班    级:         信工091              

2012 6


摘  要

随着智能手机一步步走进普通人的生活,它将成为人们获取信息的主要设备。因此,手机的应用服务将会有很大的发展空间,手机地图服务就是其中的一项。目前的地图服务主要以使用单机或者网页方式实现,这些方式不适合在户外旅游等场合下进行,给用户造成了很多的不便。Android平台提供给普通开发者非常灵活的地图展示与控制功能,这将使地图 服务的设计与实现有了更好的平台。另外,Android平台基本上是免费的,所以能够有效降低软件的成本,最终让每个用户能够自由地获取信息,也为手机地图服 务的普及做出贡献。

本文对目前应用现状进行了分析与比较,进而研究分析了Android平台的系统架构和组件模型,在此基础上,基于Android平台设计和开发了一个手机Web地图服务,该系统包括自我定位、地图模式、路线查询、地点查找四大模块。自我定位模块的功能就是把手机用户自己所在地方的地图和经纬度在界面中显示出来。行走踪迹模块的功能就是把用户经过的地方以路线图的形式给画出来。地点查找模块的功能就是查询一个地方,并把它在地图中标注出来。

本系统界面友好、操作便捷,具有良好的可扩展性和可维护性;系统经过测试,可以稳定运行,能够满足手机用户基本的地图服务需求。

关键词:Android;Activity;地图服务;Intent:布局

 

Abstract

With the mobile phone enters into the lives of ordinary people step by step,it will become the main device to obtain information.Therefore,the application services of mobile phone will have great development space,map service is one of them.At present,the map service mainly uses the stand—alone or website way to realize,these methods are not suitable for outdoor tourism,and other occasions,and give the user a lot of inconvenience.Android platform provides to the general development a function of very flexible display and control the map,which will make the design and implementation of map service have a better platform.In addition,the Android platform is basically free,so can reduce the cost of software effectively, and ultimately lets each user be able to gain the information freely, else makes a contribution to the popularization of mobile map service.

 In  this paper, there is a analysis and comparison about the status of the current applied platforms.Further analysis of the Android platform,system architecture and component model,and then to resolve the important API in Android and application of composition.On this basis,design and develop a mobile map service based on the Android platform,this system includes the self-localization,the map mode,the route inquiry, the place search.The self-localization module’s function is to display the latitude,longitude and place where mobile users are in the interface.The walking trail module’s function is to picture the place which the mobile user passes through by the form of road map.The place search module’s function is to inquire a place,and label it in  the map.

   This system user-friendly, easy to operate,has good extendibility and maintainability;the system after

the test,can be stable operation,be able to meet the mobile phone users basic map service needs.

Key Words:Android;Activity;Map Service;Intent;Layout


目  录

摘  要... 2

Abstract 3

第一章  概要分析... 1

第二章  系统分析... 2

2.1 可行性分析. ............................................................................ 2

2.1.1 技术可行性... 2

2.1.2 经济可行性... 2

2.1.3 操作可行性... 2

2.2 功能需求. .............................................................................. 2

2.2.1 系统功能... 2

2.2.2 用户特点... 2

2.3 需求分析. .............................................................................. 2

2.3.1用户体验需求... 2

2.3.2功能需求... 2

第三章  设计实现步骤(技术路线)... 3

第四章 详细设计及实现... 5

4.1 GPS系统登陆页面. .......................................................................5

4.1.1界面文件 main.xml. 5

4.1.2JAVA文件  MainActivity.java. 7

4.2 GPS系统注册页面. .......................................................................9

4.2.1界面文件 Regist.xml. 9

4.1.2 JAVA文件  RegistActivity.java. 12

4.3 GPS系统地图页面. ......................................................................15

4.3.1界面文件 others.xml. 16

4.3.2 JAVA文件  PosOverActivity.java,OthersActivity.java,LineOverLayActivity.java. 17

1)OthersActivity.java. 17

2)PosOverActivity.java. 19

3)LineOverLayActivity.java. 20

第五章 心得体会... 21


Android GPS系统

第一章  概要分析

随着第三代数字通信(3G)技术获得了广泛的接受,它为智能手机用户带来了更快的数据传输速率。智能手机不再仅是通讯网络的终端,还将成为互联网的终端。另外智能手机正一步步走进普通人的生活,这意味着智能手机将会成为人们获取信息的主要设备。因此,手机的应用服务将会有很大的发展空间,手机Web地图服务就是其中的一项,它的最大优点在于便携性好和数据的实时性。基于以上分析,设计手机地图服务具有非常好的实用意义。到目前为止,开发内嵌式地图应用的软件是相当的困难,而且往往还需要支付很高的地图厂商的版权费用,加之手机上GPS功能的不完善,导致很多可以基于当前位置来开发功能的软件少之又少。还有就是现在手机生产商众多,而且操作系统不开源,各种应用放上去非常困难。对运营商来讲,往往需要对某类手机进行单独开发,成本无形增大很多。实现开源后,与运营商结成同盟,将导致成本降低。目前,操作系统的成本占15%一20%,这对消费者是一个很大的压力,把成本降到零,这对消费者和运营商都有好处。为此,Google于20##年11月推出了一个专为移动设备设计的软件平台——Android。它的出现打破了这些格局,还提供给普通开发者非常灵活的地图展示与控制功能。

 Android是一个真正意义上的开放性移动设备综合平台,它包括操作系统、用户界面、中间件和一些关键的平台应用,拥有移动电话工作所需的全部软件。Android最大特点在于它是一个开放的体系架构,具有非常好的开发和调试环境,而且还支持各种可扩展的用户体验。

 Android平台的开放性等特点既能促进技术(包括平台自身)的创新,又有助于降低开发成本,还可以使运营商能非常方便地制定特色化的产品,以形成自己的竞争优势,这对于手机制造商来说,具有很强的吸引力。因此,它具有很大的市场发展潜力。

第二章  系统分析

2.1 可行性分析

     智能手机平台之争已经进入群雄争霸的时代,新势力的不断崛起,使其不断进步。因此,对智能手机的平台的研究与开发是当前移动计算技术发展中最为活跃的领域。 Android与PC平台存在先天的基因联系,可以很好的实现与PC设备的信息互享,更容易获得用户的广泛认可。

2.1.1技术可行性

Android的应用都基于Java开发,Java具有一次编写、到处运行的跨平台属性,只要编写一遍程序,就能够实现在所有Android设备中运行,真正做到了硬件无关性,大幅度降低了开发者的负担。Android和操作系统进行了紧密的整合,从而可以方便地使用操作系统的功能。

2.1.2经济可行性

到目前为止,开发内嵌式地图应用的软件是相当的困难,而且还需要支付很高的地图厂商的版权费用,对运营商来讲,往往需要对某类手机进行单独开发,成本无形增大很多。实现开源后,与运营商结成同盟,将导致成本降低。目前,操作系统的成本占15%一20%,这对消费者是一个很大的压力,把成本降到零,这对消费者和运营商都有好处。为此,Google于20##年11月推出了一个专为移动设备设计的软件平台——Android。它的出现打破了这些格局,还提供给普通开发者非常灵活的地图展示与控制功能。

2.1.3操作可行性

Android是一个真正意义上的开放性移动设备综合平台,它包括操作系统、用户界面、中间件和一些关键的平台应用,拥有移动电话工作所需的全部软件。Android最大特点在于它是一个开放的体系架构,具有非常好的开发和调试环境,而且还支持各种可扩展的用户体验。

2.2 功能需求

2.2.1系统功能

不同的用户有不同的使用权限。如新用户需完成注册,而已注册的用户就可直接登录GPS界面。

2.2.2用户特点

新用户和已注册的用户可以通过主界面登录系统,但因角色的不同会跳转到不同的页面。

2.3 需求分析

2.3.1用户体验需求

一个成功的Android应用程序往往需要提供良好的用户体验。良好的用户体验体现在以下几点:

     (1)界面友好      用户界面要简洁直观,并且易于操作。

     (2)快速响应      快速处理用户的输入或请求,对于有些需要较多时问的应用程序,可以在它处理时,给用户一个提示,让用户知道程序还在运行中。

     (3)无缝性        Android应用程序模型的构建是能够允许用户在不同的应用程序之问进行流畅的切换。

2.3.2功能需求

手机地图服务系统扮演着提供服务的重要角色,它需要提供友好的、方便的用户操作界面,接收用户的各项操作转化成与之对应的命令。其功能需求主要包含以下内容:

     (1)地图缩放功能         用户能够通过此缩放功能,随时放大或者缩小当前的地图信息。

     (2)视图模式切换功能     在显示地图信息的时候,应该提供给用户显示地图的普通信息和卫星信息两种常规的视图模式,用户可以根据自己的需要选择一种。

(3)自我定位功能         当手机用户来到一个地方或者迷路时,可以通过此功能来确定自己当前所在的位置信息和对应的地图信息。

     (4)行走踪迹功能         当用户出去旅游或者去一个地方又怕迷路时,可以通过此功能把走过的路线描绘出来,为回顾行程提供方便。

第三章  设计实现步骤(技术路线)

本次实训的项目是在基于eclipse工具开发的,具体实现步骤如下所示:

(1)添加一个新的android模拟器

(2)通过eclipse创建一个项目。选择File->New->Project。在菜单中选择Android->Android Project,点击Next

(3)创建一个新的Android工程。

     

(4)选择run as,选择android application,启动手机模拟器,即可看到运行效果

(5)获得Map API Key

矩形标注: 建立一个基于Google APIs的模拟器 

圆角矩形标注: 新建项目时需选择Google APIs

第四章 详细设计及实现

4.1 GPS系统登陆页面

登录运行界面:

4.1.1界面文件 main.xml

两个供输入的EditText,其中一个限定了输入类型为password;

包含两个Button,以实现登录和注册。

<?xml version="1.0" encoding="UTF-8"?>

<TableLayout

 android:background="@drawable/tupian"

android:padding="20dp"

android:shrinkColumns="0"

android:stretchColumns="1"

android:layout_height="fill_parent"

android:layout_width="fill_parent"

 android:orientation="vertical"

xmlns:android="http://schemas.android.com/apk/res/android">

<TableRow>

<TextView

android:layout_height="wrap_content"

android:layout_width="wrap_content"

android:textColor="#000000"

android:layout_marginTop="20dp"

android:layout_marginRight="20dp"

android:text="用户名:"/>

<EditText

android:layout_height="wrap_content"

android:layout_width="fill_parent"

android:layout_marginTop="20dp"

android:maxLength="10"

android:singleLine="true"

android:selectAllOnFocus="true"

android:hint="请输入姓名"

android:id="@+id/name"/>

</TableRow>

<TableRow>

<TextView

android:layout_height="wrap_content"

android:layout_width="wrap_content"

android:textColor="#000000"

android:layout_marginRight="20dp"

android:text="密码:"/>

<EditText

android:layout_height="wrap_content"

android:layout_width="fill_parent"

 android:singleLine="true"

android:selectAllOnFocus="true"

android:hint="请输入密码"

android:id="@+id/password"

android:inputType="textPassword"/>

 </TableRow>

<TableRow>

<TextView

android:layout_height="wrap_content"

android:layout_width="wrap_content"

 android:layout_marginRight="20dp"/>

<CheckBox

android:layout_height="wrap_content"

android:layout_width="fill_parent"

android:textColor="#000000"

android:text="记 住 登 陆 信 息"

android:id="@+id/cb"/>

</TableRow>

<RelativeLayout

android:layout_height="fill_parent"

 android:layout_width="fill_parent"

android:orientation="vertical">

<Button

android:layout_height="wrap_content"

android:layout_width="wrap_content"

android:text="登录"

android:id="@+id/dl"

android:layout_marginLeft="90dp"

android:layout_alignParentTop="true"

android:layout_alignParentLeft="true"/>

<Button

android:layout_height="wrap_content"

 android:layout_width="wrap_content"

 android:layout_marginRight="90dp"

android:text="注册"

android:id="@+id/button"

android:layout_alignParentTop="true"

android:layout_alignParentRight="true"/>

 </RelativeLayout>

</Table Layout>

4.1.2JAVA文件  MainActivity.java

使用main.xml布局文件,为登录和注册按钮(Button)注册事件监听,添加事件响应代码;

实现信息错误提示:Toast.makeText(MainActivity.this, ss, 1000).show();

实现Activity之间跳转设置:new AlertDialog.Builder(MainActivity.this);

Intent intent=new Intent(MainActivity.this,OthersActivity.class);

package com.ketai.table;

 import android.app.Activity;

import android.app.AlertDialog;

import android.content.Context;

import android.content.Intent;

import android.content.SharedPreferences;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import android.widget.EditText;

 public class MainActivity extends Activity {

    /** Called when the activity is first created. */

    @Override

    public void onCreate(Bundle savedInstanceState) {

       super.onCreate(savedInstanceState);

       setContentView(R.layout.main);

      

        Button button=(Button)findViewById(R.id.button);

            button.setOnClickListener(

               new View.OnClickListener(){

                  public void onClick(View v){

                      //Intent intent=new Intent(从哪儿来.this, 到哪里去.class);

                      Intent intent=new Intent(MainActivity.this,RegistActivity.class);

                      //跳转

                      startActivity(intent);

                  }

               }

               );

            Button b=(Button)findViewById(R.id.dl);

            b.setOnClickListener(

                  new View.OnClickListener() {

                     private Object password;

                     public void onClick(View v) {

                  final EditText nameEt=(EditText)findViewById(R.id.name);

                  final EditText passwordEt=(EditText)findViewById(R.id.password);

                  String uname=nameEt.getText().toString();

                  String upass=passwordEt.getText().toString();

                  SharedPreferences references=getSharedPreferences("account", Context.MODE_WORLD_READABLE+Context.MODE_WORLD_WRITEABLE);

                  String name=references.getString("username", "");

                  String pass=references.getString("password", "");

                  if(name.equals(uname))

                  {

                     if(pass.equals(upass))

                     {

                         Intent intent=new Intent(MainActivity.this,OthersActivity.class);

                         startActivity(intent);

                     }

                     else{

                        

                            new AlertDialog.Builder(MainActivity.this)

                            .setIcon(R.drawable.ic_dialog_menu_generic)//设置图片

                            .setTitle("错误提示")//设置标题

                            .setMessage("您的密码错误,请重新输入")//设置提示信息

                            .setPositiveButton("确定", null)//设置第1个按钮

                            .show();//显示对话框

                         //String sb="您的密码错误,请重新输入";

                         //Toast.makeText(MainActivity.this, sb, 1000).show();

                         }

                  }

                     else{

                          new AlertDialog.Builder(MainActivity.this)

                         .setIcon(R.drawable.ic_dialog_menu_generic)//设置图片

                         .setTitle("错误提示")//设置标题

                         .setMessage("无此用户名,请重新输入")//设置提示信息

                         .setPositiveButton("确定", null)//设置第1个按钮

                         .show();//显示对话框

                           

                         //String ss="无此用户名, 请重新输入";

                         //Toast.makeText(MainActivity.this, ss, 1000).show();

                         }

                     }

                  }

            );

    }

}

       

  

4.2 GPS系统注册页面

注册运行界面:

         

4.2.1界面文件 Regist.xml

两个供输入的EditText,其中一个限定了输入类型为password;

包含两个Button,以实现登录和注册;

设置下拉列表,实现省份和城市的联级;

<?xml version="1.0" encoding="UTF-8"?>

-<LinearLayout

android:background="@drawable/pict"

android:layout_height="fill_parent"

android:layout_width="fill_parent"

android:orientation="vertical"

xmlns:android="http://schemas.android.com/apk/res/android">

<LinearLayout

android:layout_height="wrap_content"

android:layout_width="fill_parent"

android:orientation="horizontal">

<LinearLayout

android:layout_height="wrap_content"

android:layout_width="fill_parent"

android:orientation="horizontal">

 <TextView

 android:layout_height="wrap_content"

 android:layout_width="wrap_content"

android:textColor="#000000"

android:text="密 码:"/>

<EditText

 android:layout_height="wrap_content"

android:layout_width="fill_parent"

android:maxLength="10"

android:singleLine="true"

android:id="@+id/upass"

android:inputType="textPassword"/>

 </LinearLayout>

<LinearLayout

 android:layout_height="wrap_content"

 android:layout_width="fill_parent"

 android:orientation="horizontal">

<TextView

android:layout_height="wrap_content"

android:layout_width="wrap_content"

android:textColor="#000000" android:text="性别:"

android:layout_marginTop="12dp"/>

<RadioGroup

android:layout_height="wrap_content"

 android:layout_width="wrap_content"

 android:orientation="horizontal"

android:id="@+id/rg">

<RadioButton

 android:layout_height="wrap_content"

android:layout_width="wrap_content"

android:textColor="#000000"

 android:text="男"

android:id="@+id/man"

android:checked="true"/>

<RadioButton

android:layout_height="wrap_content"

android:layout_width="wrap_content"

android:textColor="#000000"

 android:text="女"

android:id="@+id/woman"/>

 </RadioGroup>

 </LinearLayout>

<LinearLayout

android:layout_height="wrap_content"

 android:layout_width="fill_parent"

android:orientation="horizontal"

android:id="@+id/linear">

 <TextView

android:layout_height="wrap_content"

android:layout_width="wrap_content"

 android:textColor="#000000"

android:text="爱好:"

android:layout_marginRight="6dp"/>

<CheckBox

android:layout_height="wrap_content"

android:layout_width="wrap_content"

android:textColor="#000000"

android:text="体育"

android:id="@+id/sport"/>

<CheckBox

android:layout_height="wrap_content"

 android:layout_width="wrap_content"

 android:textColor="#000000"

 android:text="音乐"

 android:id="@+id/music"/>

<CheckBox

android:layout_height="wrap_content"

 android:layout_width="wrap_content"

 android:textColor="#000000"

android:text="游戏"

android:id="@+id/game"/>

</LinearLayout>

<LinearLayout

android:layout_height="wrap_content"

 android:layout_width="fill_parent"

 android:orientation="horizontal"

 android:id="@+id/linear">

<TextView

android:layout_height="wrap_content"

android:layout_width="wrap_content"

android:textColor="#000000"

android:text="省份:"

android:layout_marginRight="6dp"/>

 <Spinner

android:layout_height="wrap_content"

android:layout_width="fill_parent"

android:id="@+id/province"

android:prompt="@string/province"/>

</LinearLayout>

<LinearLayout

android:layout_height="wrap_content"

android:layout_width="fill_parent"

android:orientation="horizontal"

android:id="@+id/liner">

<TextView

 android:layout_height="wrap_content"

android:layout_width="wrap_content"

android:textColor="#000000"

android:text="城市:"

android:layout_marginRight="6dp"/>

 <Spinner

 android:layout_height="wrap_content"

 android:layout_width="fill_parent"

android:id="@+id/city"

android:prompt="@string/city"/>

 </LinearLayout>

<LinearLayout

android:layout_height="wrap_content"

android:layout_width="fill_parent"

 android:orientation="horizontal"

 android:gravity="center">

<Button

android:layout_height="wrap_content"

android:layout_width="wrap_content"

android:text="注册"

android:id="@+id/btn"/>

<Button

android:layout_height="wrap_content"

android:layout_width="wrap_content"

android:text="返回"

android:id="@+id/bt"/>

</LinearLayout>

 </LinearLayout>

4.1.2 JAVA文件  RegistActivity.java

实现Activity之间跳转设置:

Intent intent=new Intent(RegistActivity.this,MainActivity.class);

实现Activity之间数据封装传输:

editor.putString("username", uname);

                editor.putString("password", password);

                editor.putString("sex", sex);

                editor.putString("hobbys", hobbys);

                editor.putString("province", province);

                editor.putString("city", city);

                editor.commit();

package com.ketai.table;

import java.util.ArrayList;

import java.util.HashMap;

import java.util.Map;

import android.app.Activity;

import android.content.Context;

import android.content.Intent;

import android.content.SharedPreferences;

import android.content.SharedPreferences.Editor;

import android.os.Bundle;

import android.util.Log;

import android.view.View;

import android.widget.AdapterView;

import android.widget.ArrayAdapter;

import android.widget.Button;

import android.widget.CheckBox;

import android.widget.EditText;

import android.widget.LinearLayout;

import android.widget.RadioButton;

import android.widget.RadioGroup;

import android.widget.Spinner;

import android.widget.TextView;

import android.widget.Toast;

import android.widget.AdapterView.OnItemSelectedListener;

 public class RegistActivity extends Activity {

  private View button;

  /** Called when the activity is first created. */

    @Override

    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.regist);

        //因为后续相关控件要在Button的侦听器(采用的匿名内部类的方式)中访问,所以下面的变量前要加final关键字

        //获得用户名 <EditText android:id="@+id/uname" .../>

        final EditText unameEt=(EditText)findViewById(R.id.uname);

        //获得密码框 <EditText android:id="@+id/upass" .../>

        final EditText upassEt=(EditText)findViewById(R.id.upass);

        //获得RadioButton所在的容器 RadioGroup <RadioGroup android:id="@+id/rg" .../>

        final RadioGroup rg=(RadioGroup)findViewById(R.id.rg);

        //获得CheckBox所在的容器 <LinearLayout android:id="@+id/linear" .../>

        final LinearLayout linear=(LinearLayout)findViewById(R.id.linear);

        //获得Spinner <Spinner android:id="@+id/province" .../>

        final Spinner provinceSp=(Spinner)findViewById(R.id.province);

        //准备初始化Spinner的数据

        final Spinner citySp=(Spinner)findViewById(R.id.city);

        /*String[] arrays=new String[]{"江苏","山东","浙江"};

        //第二个参数是当下拉列表没有展开时采用的layout

        ArrayAdapter adapter=

        new ArrayAdapter(this,android.R.layout.simple_spinner_item,arrays);*/

       /* final List<String> data=new ArrayList<String>();

        data.add("江苏");

        data.add("山东");

        data.add("浙江");

        ArrayAdapter adapter=new ArrayAdapter(this,android.R.layout.simple_spinner_item,data);*/

        final Map<String,String[]> datas=new HashMap<String,String[]>();

        datas.put("江苏", new String[]{"南京","苏州","无锡"});

        datas.put("山东", new String[]{"济南","青岛","烟台"});

        datas.put("浙江", new String[]{"杭州","温州","嘉兴"});

        //实例化Adapter

        ArrayAdapter proviceAdapter=new ArrayAdapter(this,android.R.layout.simple_spinner_item,new ArrayList(datas.keySet()));

        //设置Spinner下拉的样式

        proviceAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

        provinceSp.setAdapter(proviceAdapter);

        //将Adapter与Spinner绑定

        provinceSp.setOnItemSelectedListener(new OnItemSelectedListener() {

        public void onItemSelected(AdapterView<?> parent, View view,int position, long id) {

            Spinner sp=(Spinner)parent;

            Log.i("MainActivity", String.valueOf(sp.getId()));

            TextView tv=(TextView)view;

            String province=tv.getText().toString();//获得省份

            String[] citys=datas.get(province);//根据省份获得城市

            ArrayAdapter cityAd=new ArrayAdapter(RegistActivity.this,android.R.layout.simple_spinner_item,citys);

            cityAd.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

            citySp.setAdapter(cityAd);

         }

         @Override

         public void onNothingSelected(AdapterView<?> parent) {

            // TODO Auto-generated method stub

         }

        

        }

  );

        //获得按钮<Button android:id="@+id/btn"..>

        Button btn=(Button)findViewById(R.id.btn);

        //向按钮注册单击事件

        btn.setOnClickListener(

            new View.OnClickListener() {

                public void onClick(View v) {                   

                   //获得用户名:调用EditText的getText()方法

                   String uname=unameEt.getText().toString();

                    //获得密码:调用EditText的getText()方法

                   String password=upassEt.getText().toString();

                    //获得性别:获得父容器,然后遍历父容器中所有RadioButton,找到选中的并获得值

                   String sex="";

                   for(int i=0;i<rg.getChildCount();i++)

                   {

                       RadioButton rdo=(RadioButton)rg.getChildAt(i);

                       if(rdo.isChecked())

                       {

                          sex=rdo.getText().toString();

                          break;//跳出循环

                       }

                   }

                    //获得爱好:获得父容器,然后遍历父容器中所有CheckBox,找到选中的并获得值

                   String hobbys="";

                   for(int i=0;i<linear.getChildCount();i++)

                    {

                       if(linear.getChildAt(i) instanceof CheckBox)

                       {

                          CheckBox chk=(CheckBox)linear.getChildAt(i);

                          if(chk.isChecked())

                          {

                              hobbys+=chk.getText();

                          }

                       }

                   }

               

                   //获得省份:调用Spinner的getSelectedItem()方法

                   String province=(String)provinceSp.getSelectedItem();

                   String city=(String)citySp.getSelectedItem();

                    //将所有信息串联起来:用"+"进行连接

                   String result=uname+" "+password+" "+province+" "+city+" "+sex+"  "+hobbys;

                    //提示信息给用户

                   Toast.makeText(RegistActivity.this, result, 1000).show();

                   SharedPreferences references

                       =RegistActivity.this.getSharedPreferences("account", Context.MODE_WORLD_READABLE+Context.MODE_WORLD_WRITEABLE);

                   Editor editor=references.edit();

                   editor.putString("username", uname);

                   editor.putString("password", password);

                   editor.putString("sex", sex);

                   editor.putString("hobbys", hobbys);

                   editor.putString("province", province);

                   editor.putString("city", city);

                    editor.commit();

                }

        }

                    );

        Button bt=(Button)findViewById(R.id.bt);

        bt.setOnClickListener(

            new View.OnClickListener() {

                public void onClick(View v) {

                   Intent intent=new Intent(RegistActivity.this,MainActivity.class);

                   startActivity(intent);            

  }

            }

        );

    }

    }

4.3 GPS系统地图页面

地图运行界面:

4.3.1界面文件 others.xml

<?xml version="1.0" encoding="UTF-8"?>

<LinearLayout

android:layout_height="fill_parent"

android:layout_width="fill_parent"

android:orientation="vertical"

xmlns:android="http://schemas.android.com/apk/res/android">

<TextView

android:layout_height="wrap_content"

android:layout_width="fill_parent"

android:text="@string/hello"/>

<com.google.android.maps.MapView

android:layout_height="340dp"

android:layout_width="fill_parent"

android:apiKey="0c1so2x4H3eKh9eJ63f47bw_b1vn191PSzBcQ5A"

android:clickable="true"

android:id="@+id/map"/>

<RadioGroup

android:layout_height="wrap_content"

android:layout_width="fill_parent"

android:orientation="horizontal"

android:id="@+id/rg">

<RadioButton

android:layout_height="wrap_content"

android:layout_width="wrap_content"

android:text="普通"

android:id="@+id/traffic"/>

<RadioButton

android:layout_height="wrap_content"

android:layout_width="wrap_content"

android:text="卫星"

android:id="@+id/statellite"/>

</RadioGroup>

<LinearLayout

android:layout_height="wrap_content"

android:layout_width="fill_parent"

android:orientation="horizontal"

android:id="@+id/linear">

<TextView

android:layout_height="wrap_content"

android:layout_width="wrap_content"

android:text="连接线:"/>

<CheckBox

android:layout_height="wrap_content"

android:layout_width="fill_parent"

android:text="是"

android:id="@+id/cb"/>

</LinearLayout>

</LinearLayout>

4.3.2 JAVA文件  PosOverActivity.java,OthersActivity.java,LineOverLayActivity.java

1)OthersActivity.java

getController():返回该MapView关联的MapController对象,

MapController对象可对该MapView进行控制,如将地图控制到指定位置,控制地图放大缩小等。

setStatellite(Boolean on): 设置是否显示卫星地图

setTraffic(Boolean on):设置是否显示交通情况

List<Overlay> getOverlays(): 返回全部的OverLay

MapController的常用方法:

setCenterTo(GeoPoint point): 将地图以指定位置为中心

animateTo(GeoPoint point): 定位地图到指定位置.

setZoom(int scale); 设置地图的缩放级别

package com.ketai.table;

import java.util.ArrayList;

import java.util.List;

import android.content.Context;

import android.graphics.Bitmap;

import android.graphics.BitmapFactory;

import android.location.Location;

import android.location.LocationListener;

import android.location.LocationManager;

import android.os.Bundle;

import android.widget.CheckBox;

import android.widget.RadioButton;

import android.widget.RadioGroup;

import com.google.android.maps.GeoPoint;

import com.google.android.maps.MapActivity;

import com.google.android.maps.MapController;

import com.google.android.maps.MapView;

import com.google.android.maps.Overlay;

public class OthersActivity extends MapActivity {

    CheckBox cb;

    List<GeoPoint> pointList=new ArrayList<GeoPoint>();

    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.others);

        final CheckBox cb=(CheckBox)findViewById(R.id.cb);

        //获得MapView对象

        final MapView mv=(MapView)findViewById(R.id.map);

        mv.setBuiltInZoomControls(true);//允许内置的放大缩小控件

        //获得此MapView相关联的MapController

        final MapController controller=mv.getController();

        //以指定点为地图中心,此处以南京的坐标作为中心

        controller.setCenter(new GeoPoint((int)(32.032500*1E6),(int)(119.640000*1E6)));

        //设置地图的缩放级别

        controller.setZoom(10);

        //获得单选按钮组

        RadioGroup rg=(RadioGroup)findViewById(R.id.rg);

        //给RadioGroup注册OnCheckedChange事件

        rg.setOnCheckedChangeListener(

          new RadioGroup.OnCheckedChangeListener() {

            public void onCheckedChanged(RadioGroup group, int checkedId) {

               //取出选中状态的RadioButton

              RadioButton rdo=(RadioButton)OthersActivity.this.findViewById(checkedId);

              if(rdo.isChecked())

              {

                  if(rdo.getText().toString().equals("卫星"))//判断选中的哪个按钮

                  {

                     mv.setSatellite(true);//设置地图采用普通模式

                  }

                  else

                  {

                     mv.setSatellite(false);//设置地图采用卫星模式

                  }

              }

           }

        }

     );

        //读取图片到位图对象中

        final Bitmap posBitmap=BitmapFactory.decodeResource(getResources(), R.drawable.pos);

        //获得定位管理器

        LocationManager lm=(LocationManager)getSystemService(Context.LOCATION_SERVICE);

        lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,

              new LocationListener() {

                  public void onStatusChanged(String provider, int status, Bundle extras) {

                     // TODO Auto-generated method stub

                  }

                  public void onProviderEnabled(String provider) {

                     // TODO Auto-generated method stub

                  }

                  public void onProviderDisabled(String provider) {

                     // TODO Auto-generated method stub

                  }

                 

                  public void onLocationChanged(Location location) {

                     // TODO Auto-generated method stub

                     //获得地图上的当前已经存在的所有图层

                     List<Overlay> lays=mv.getOverlays();

                     //清空原有的图层

                     lays.clear();

                     //获得要添加的点信息

                     GeoPoint point=new GeoPoint((int)(location.getLatitude()*1E6),(int)(location.getLongitude()*1E6));

                     pointList.add(point);//将新的坐标添加到集合中

                     //通过循环,依次绘出集合中的每一点

                     for(int i=0;i<pointList.size();i++)

                     {

                         //实例化一个新的图层,新图层会在指定point画上posBitmap

                         PosOverActivity newLay=new PosOverActivity(posBitmap, pointList.get(i));

                         //将新图层添加到MapView上

                         lays.add(newLay);

                         if(i==pointList.size()-1)//判断是否为最后一点

                         {

                            //把MapView的中心设置成当前点

                            controller.animateTo(point);

                         }

                     }

                     if(cb.isChecked())

                     {

                         lays.add(new LineOverLayActivity(pointList));

                     }

                  }

              }

              );

    }

    protected boolean isRouteDisplayed() {

       return false;

    }

}

2)PosOverActivity.java

准备工作: 将pos.gif 拷贝到 /res/drawable-mdpi下

实现方式: 继承 OverLay类,重写其 draw()方法, 在draw()方法中画自定义的图形

绘图的3步骤: 1. 获取MapView上的屏幕坐标与经纬度坐标间的投影关系

               2. 调用Projection的toPixels方法把经纬度坐标转换成屏幕坐标

               3. 调用Canvas的drawBitmap方法在指定位置绘制图片

package com.ketai.table;

import android.graphics.Bitmap;

import android.graphics.Canvas;

import android.graphics.Point;

import com.google.android.maps.GeoPoint;

import com.google.android.maps.MapView;

import com.google.android.maps.Overlay;

import com.google.android.maps.Projection;

 public class PosOverActivity extends Overlay{

    private Bitmap posBitmap;//要画的图像

    private GeoPoint gp;//要画的位置

    public PosOverActivity(Bitmap posBitmap, GeoPoint gp) {

       super();

       this.posBitmap = posBitmap;

       this.gp = gp;

    }

    public void draw(Canvas canvas, MapView mapView, boolean shadow) {

       if(!shadow)

       {

           //获取MapView上的屏幕坐标与经纬度坐标间的投影对象

           Projection proj=mapView.getProjection();

           //实例化一个点

           Point p=new Point();

           //将真实的地理坐标转换成屏幕坐标

           proj.toPixels(gp, p);

           //以左上角为坐标系原点,在指定位置画图

           canvas.drawBitmap(posBitmap, p.x-posBitmap.getWidth()/2,p.y-posBitmap.getHeight()/2,null);

       }

    }

}

3)LineOverLayActivity.java

package com.ketai.table;

import java.util.ArrayList;

import java.util.List;

import android.graphics.Canvas;

import android.graphics.Color;

import android.graphics.Paint;

import android.graphics.Path;

import android.graphics.Point;

import com.google.android.maps.GeoPoint;

import com.google.android.maps.MapView;

import com.google.android.maps.Overlay;

import com.google.android.maps.Projection;

public class LineOverLayActivity extends Overlay{

    private List<GeoPoint> pointList=new ArrayList<GeoPoint>();

    //通过构造函数传入要画线的点的集合

    public LineOverLayActivity(List<GeoPoint> pointList) {

       super();

       this.pointList = pointList;

    }

    public void draw(Canvas canvas, MapView mapView, boolean shadow) {

       if(shadow==false){

           Paint paint=new Paint();//实例化一个画笔

           paint.setColor(Color.RED);//设置画笔的颜色

           paint.setStyle(Paint.Style.STROKE);//设置风格

           paint.setStrokeWidth(2);//设置宽度

           Path path=new Path();

           for(int i=0;i<pointList.size();i++)

           {

              Point point=new Point();

              //获得投影对象

              Projection projection = mapView.getProjection();

              //将地理上的经纬度投影为屏幕上的点

              projection.toPixels(pointList.get(i), point);

              if(i==0)//第1个点

                  path.moveTo(point.x, point.y);//移到第一个点

              else

              {  

                  path.lineTo(point.x, point.y);//从前一个点画到下一个点        

              }

           }

           canvas.drawPath(path, paint);//用画笔将路径画到画布上

       }

      

    }

}

第五章 心得体会

一周的实训马上就过去了,虽然一天将近十个小时的实训时间,让我们感到很累,但是还是觉得这点累还是值得的。这次的实训不再是像以往那样,由学校的老师来教我们做项目,而是由外面企业的老师来教我们,这让我有了一点点兴趣。这次的实训,是教我们现在很流行的android,android是由谷歌推出的运用在手机上的操作系统,现在,这种安装了android的手机相当风靡。当我听到这周的实训要教这个的时候,有点兴奋,因为对android的编程有兴趣。

通过这次的实训,知道了android的发展史,android是谷歌于20##年11月5日宣布的基于linux平台的开源手机操作系统,该平台由操作系统、中间件、用户界面、和应用软件程序组成,号称是首个为移动终端打造的真正开放和完整的移动软件它采用了软件堆层(software stack,又名软件叠层)的架构,主要分为三部分。底层Linux内核只提供基本功能,其他的应用软件则由各公司自行开发,部分程序以Java编写。现在又很多手机上都是安装了android系统,有谷歌,三星,摩托罗拉,华为等等。

通过这次的实训,学到了很多,因为我们都是第一次接触android,所以老师先给我们讲了一个基本上每个程序语言都要编的,经典的程序,helloworld。通过这个小程序,我们知道了如何去创建一个android的项目,了解了android项目里的每个文件夹和文件的作用。教了一些常用的控件的使用,如:TextView,Button等等。然后老师又教我们如何布局,认识了linearlayout,tablelayout, AbsoluteLayout, RelativeLayout四种布局,分别为线型布局,表格布局,绝对布局和相对布局,并知道了如何通过这四种布局的相互嵌套来使程序的界面更加的友好,更加的让用户接受。这次的实训,做了很多的程序。

由于这次的实训时间真的太短,当我刚刚对android有点入门的时候,实训时间却已经要结束了,这次的实训学到了很多,但是对难一点的却还有些不知道,这让我有点小小的失望。通过这次的实训,不仅学到了新知识,更对已经就学过的JAVA又加深了一点印象。现在自己也能利用已有的知识,编一些简单的程序,通过这次的实训,让我对以后选择软件开发的行业更加坚定了。打算自己在实训好后还要在学。

这次的实训比前几次的实训都要累,但是累的值得,再说,没有一定的付出,哪来的收获,只有当付出了,才会有收获。

更多相关推荐:
Android实训报告

通信与电子信息专业实训报告项目名称基于Android的游戏开发班级10通信1班姓名学号指导教师成绩实训时间年月日目录一实训目的及其意义311目的及意义312研究现状3二实训主要任务重点及难点421任务422重点...

android实习报告

实习报告实习目的:生产实习是计算机科学与技术专业重要的实践性教学活动,其目的是使学生们进一步加深对所学知识的理解,理论联系实际,巩固所学有关计算机基础理论知识和基本技能,学习有关计算机最新技术方面的应用,增强学…

Android实训实验报告

报告编号第5组综合课程设计报告基于Android平台的记事本的设计与实现学生姓名指导教师所在系电子工程系所学专业计算机科学与技术班级20xx年12月摘要基于Android平台的记事本的设计与实现随着科学技术的不...

android实训报告

多媒体技术综合实训课题名称多媒体展示系统的设计与开发计算机与软件学院计算机多媒体游戏软件设计与开发计媒10211002553224学号10025532061002553218院系专业班级100255321210...

Android实训报告

Android学院班级学号姓名实训报告目录一实训背景及目的要求311背景简介312实训目的及要求3二设计思路321设计题目322功能分析423模块划分4三设计实现及代码分析431第一个Activity4311布...

android本科实验报告

本科实验报告课程名称实验项目实验地点专业班级学生姓名指导教师Android设计与开发Android课程实验学号年月日太原理工大学学生实验报告太原理工大学学生实验报告太原理工大学学生实验报告太原理工大学学生实验报...

android实习报告

实习项目名称3GAndriod实习学时同组学生姓名实习地点实习日期成绩批改教师批改时间实习报告一实习目的1掌握android系统开发的一些常用知识2拥有独立解决开发中遇到问题的能力3熟悉android软件开发流...

Android实验格式简易计算器实验报告

实验报告20xx20xx学年第2学期课程名称嵌入式操作系统实验题目简易计算器的设计与实现专业计算机科学与技术信息处理是什么专业写什么专业班级计算本1101按自己班级填写日期填写20xx年4月8日实验题目简易计算...

android实训设计报告

实训报告学生姓名李佳奇学号33专业班级网络091课程名称学年学期指导教师2012年12月实训成绩评定表目录一实训背景及目的要求111背景简介112实训目的及要求1二设计思路221设计题目222功能分析223模块...

Android 实验报告三

浙江农林大学暨阳学院实验报告三课程名称实验类别姓名班级学号Service实验目的1熟悉service和broadcast实验题目熟悉service的生命周期启动方式和停止方式Broadcast几种不同注册方式实...

android实训报告

实训总结通过这为期三周的android实训我们学会了用eclipse的android编程方法以及开发用的MVC变成开发模式和团队开发所使用的SVN团队编程版本控制器在以后学习过程中希望大家多多提点我和我们组的组...

Andriod毕业实习报告

毕业实习报告专业班级学号学生姓名指导教师实习时间实习成绩说明1实习指导教师由学院校内教师担任负责组织实习学生管理参加实习答辩实习成绩评定给出实习评语等工作2实习报告由武汉工程大学计算机科学与工程学院提供基本格式...

android实训报告(31篇)