简单安卓浏览器开发实验报告.docx

上传人:b****2 文档编号:13979317 上传时间:2023-06-19 格式:DOCX 页数:10 大小:572.02KB
下载 相关 举报
简单安卓浏览器开发实验报告.docx_第1页
第1页 / 共10页
简单安卓浏览器开发实验报告.docx_第2页
第2页 / 共10页
简单安卓浏览器开发实验报告.docx_第3页
第3页 / 共10页
简单安卓浏览器开发实验报告.docx_第4页
第4页 / 共10页
简单安卓浏览器开发实验报告.docx_第5页
第5页 / 共10页
简单安卓浏览器开发实验报告.docx_第6页
第6页 / 共10页
简单安卓浏览器开发实验报告.docx_第7页
第7页 / 共10页
简单安卓浏览器开发实验报告.docx_第8页
第8页 / 共10页
简单安卓浏览器开发实验报告.docx_第9页
第9页 / 共10页
简单安卓浏览器开发实验报告.docx_第10页
第10页 / 共10页
亲,该文档总共10页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

简单安卓浏览器开发实验报告.docx

《简单安卓浏览器开发实验报告.docx》由会员分享,可在线阅读,更多相关《简单安卓浏览器开发实验报告.docx(10页珍藏版)》请在冰点文库上搜索。

简单安卓浏览器开发实验报告.docx

简单安卓浏览器开发实验报告

简单安卓浏览器开发实验报告

实验报告

学年学期:

课程名称:

移动互联网

指导老师:

学院:

计算机学院

班级:

学号:

姓名:

 

湖南工业大学

 

二.系统需求

1.界面需求

(1)简洁美观

(2)易于操作

(3)使用方便

2.性能需求

能够运行android2.3的手机

3.可行性需求

Android是一个包含操作系统、中介架构层及应用程序所产生出来的软件堆栈架构。

由下而上,其核心为嵌入式Linux2.6作业系统,向上搭配Google为Android开发的类库及Android运行时,再配合应用程序架构,来开发各种不同的应用程序。

4.运行环境需求

软件基本运行环境为智能手机android 操作系统 

 

实验内容(实验原理、运用的理论知识和数据、算法、程序、步骤和方法)

三.功能需求

(1)能够联网进行数据交换

(2)能够获取网页数据并展示

(3)能够对网页进行手动的刷新

(4)能够前进到网页的下一页

(5)能够后退到上一个访问的网页

实验内容(实验原理、运用的理论知识和数据、算法、程序、步骤和方法)

四、实现程序

界面代码:

android="

xmlns:

tools="

android:

layout_width="match_parent"

android:

layout_height="match_parent"

android:

orientation="vertical"

tools:

context=".MainActivity">

android:

layout_width="wrap_content"

android:

layout_height="25dp"

android:

layout_gravity="center"

android:

text="网络工程移动互联网技术实验"/>

android:

layout_width="match_parent"

android:

layout_height="40dp"

android:

orientation="horizontal"

>

android:

id="@+id/bt_left"

android:

text="@string/left"

android:

layout_width="0dp"

android:

padding="0dp"

android:

layout_weight="1"

android:

layout_height="match_parent"

/>

android:

id="@+id/bt_right"

android:

text=">"

android:

padding="0dp"

android:

layout_width="0dp"

android:

layout_weight="1"

android:

layout_height="match_parent"

/>

android:

id="@+id/bt_refresh"

android:

padding="0dp"

android:

text="刷新"

android:

layout_width="0dp"

android:

layout_weight="2"

android:

layout_height="wrap_content"

/>

android:

id="@+id/et_path"

android:

layout_width="0dp"

android:

layout_weight="8"

android:

singleLine="true"

android:

layout_height="match_parent"

/>

android:

id="@+id/bt_entry"

android:

text="前往"

android:

layout_width="0dp"

android:

layout_weight="2"

android:

layout_height="match_parent"

/>

android:

id="@+id/pd"

android:

visibility="gone"

style="?

android:

attr/progressBarStyleHorizontal"

android:

layout_width="match_parent"

android:

layout_height="3dp"/>

android:

id="@+id/webview"

android:

layout_width="match_parent"

android:

layout_height="match_parent"

/>

主要代码:

importandroid.app.Activity;

importandroid.content.Intent;

importandroid.graphics.Bitmap;

importandroid.os.Bundle;

importandroid.view.Menu;

importandroid.view.View;

publicclassMainActivityextendsActivityimplementsOnClickListener{

privateEditTextet_path;

privateButtonbt_entry;

privateWebViewwebview;

privateButtonbt_left;

privateButtonbt_right;

privateButtonbt_refresh;

privateProgressBarpd;

@Override

protectedvoidonCreate(BundlesavedInstanceState){

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

et_path=(EditText)findViewById(R.id.et_path);

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

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

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

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

pd=(ProgressBar)findViewById(R.id.pd);

webview=(WebView)findViewById(R.id.webview);

bt_entry.setOnClickListener(this);

bt_left.setOnClickListener(this);

bt_right.setOnClickListener(this);

bt_refresh.setOnClickListener(this);

initSettings();

}

privatevoidinitSettings(){

webview.setWebViewClient(newWebViewClient(){

@Override

publicbooleanshouldOverrideUrlLoading(WebViewview,Stringurl){

et_path.setText(url);

returnsuper.shouldOverrideUrlLoading(view,url);

}

@Override

publicvoidonPageStarted(WebViewview,Stringurl,Bitmapfavicon){

pd.setVisibility(View.VISIBLE);

super.onPageStarted(view,url,favicon);

}

@Override

publicvoidonPageFinished(WebViewview,Stringurl){

pd.setVisibility(View.GONE);

super.onPageFinished(view,url);

addImageClickListener(webview);

}

});

webview.setWebChromeClient(newWebChromeClient(){

@Override

publicvoidonReceivedTitle(WebViewview,Stringtitle){

//TODOAuto-generatedmethodstub

super.onReceivedTitle(view,title);

}

@Override

publicvoidonProgressChanged(WebViewview,intnewProgress){

pd.setProgress(newProgress);

super.onProgressChanged(view,newProgress);

}

});

WebSettingssettings=webview.getSettings();

settings.setJavaScriptEnabled(true);

webview.addJavascriptInterface(newAndroidNative(),"imagelistener");

}

privatevoidaddImageClickListener(WebViewwebView){

webView.loadUrl("javascript:

(function(){"

+"varobjs=document.getElementsByTagName(\"img\");"

+"for(vari=0;i

+"objs[i].onclick=function()"+"{"

+"window.imagelistener.openImage(this.src);"+//通过js代码找到标签为img的代码块,设置点击的监听方法与本地的openImage方法进行连接

"}"+"}"+"})()");

}

publicclassAndroidNative{

@JavascriptInterface

publicvoidopenImage(StringimageSrc){

Toast.makeText(getApplicationContext(),imageSrc,Toast.LENGTH_SHORT).show();

Intentintent=newIntent();

intent.putExtra("path",imageSrc);

intent.setClass(getApplicationContext(),ImageActivity.class);

startActivity(intent);

}

}

@Override

publicbooleanonCreateOptionsMenu(Menumenu){

//Inflatethemenu;thisaddsitemstotheactionbarifitispresent.

getMenuInflater().inflate(R.menu.main,menu);

returntrue;

}

@Override

publicvoidonClick(Viewv){

switch(v.getId()){

caseR.id.bt_entry:

Stringurl="http:

//"+et_path.getText().toString();

Toast.makeText(getApplicationContext(),url,Toast.LENGTH_SHORT).show();

webview.loadUrl(url);

break;

caseR.id.bt_left:

Toast.makeText(getApplicationContext(),"向后",Toast.LENGTH_SHORT).show();

webview.goBack();

break;

caseR.id.bt_right:

Toast.makeText(getApplicationContext(),"向前",Toast.LENGTH_SHORT).show();

webview.goForward();

break;

caseR.id.bt_refresh:

Toast.makeText(getApplicationContext(),"刷新",Toast.LENGTH_SHORT).show();

webview.reload();

break;

default:

break;

}

}

@Override

publicvoidonBackPressed(){

if(webview.canGoBack()){

webview.goBack();

}else{

super.onBackPressed();

}

}

}

实验内容(实验原理、运用的理论知识和数据、算法、程序、步骤和方法)

五、功能展示

刷新功能

 

前进功能

后退功能

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 小学教育 > 语文

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2