Android intent and activity 经典程序

#massage_box {
position: absolute;
left: expression((body.clientwidth-350)/ 2 );
top: expression((body.clientheight-200)/ 2 );
width: 350px;
height: 200px;

z-index: 2;
visibility: hidden
}

#mask {
position: absolute;
top: 0;
left: 0;
width: expression(body.scrollwidth);
height: expression(body.scrollheight);
background: #d3ddea;
filter: alpha(opacity =50);
z-index: 1;
visibility: hidden
}
//数据写入intentintent openwelcomeactivityintent=new intent();bundle mybundelforname=new bundle();mybundelforname.putstring("key_name",inname.gettext().tostring());mybundelforname.putstring("key_age",inage.gettext().tostring());openwelcomeactivityintent.putextras(mybundelforname);openwelcomeactivityintent.setclass(androidbundel.this, welcome.class);startactivity(openwelcomeactivityintent);//从intent 中获取数据bundle mybundelforgetname=this.getintent().getextras();string name=mybundelforgetname.getstring("key_name");


package zyf.android.study;import ……import android.content.intent;import android.net.uri;import android.view.view.onclicklistener;public class androidstudy_two extends activity {@overridepublic void oncreate(bundle savedinstancestate) {super.oncreate(savedinstancestate);setcontentview(r.layout.main);final edittext inname = (edittext) findviewbyid(r.id.name);final textview result = (textview) findviewbyid(r.id.result);button button_start_browser = (button) findviewbyid(r.id.submit_tonet);button button_login=(button) findviewbyid(r.id.show_login);button button_showloginname=(button)findviewbyid(r.id.submit_toshowloingname);button_start_browser.setonclicklistener(new onclicklistener(){@overridepublic void onclick(view v) {uri myuri = uri.parse("http://www.flashwing.net");intent openbrowserintent = new intent(intent.action_view,myuri);startactivity(openbrowserintent);}});button_login.setonclicklistener(new onclicklistener(){@overridepublic void onclick(view v) {intent openwelcomeactivityintent=new intent();openwelcomeactivityintent.setclass(androidstudy_two.this,welcome.class);startactivity(openwelcomeactivityintent);}});button_showloginname.setonclicklistener(new onclicklistener(){@overridepublic void onclick(view v) {result.settext(inname.gettext()+"欢迎您进入");}});}}



使用bundle在activity间传递数据2从源请求activity 中通过一个intent 把一个服务请求传到目标activity 中//数据写入intentintent openwelcomeactivityintent=new intent();bundle mybundelforname=new bundle();mybundelforname.putstring("key_name",inname.gettext().tostring());mybundelforname.putstring("key_age",inage.gettext().tostring());openwelcomeactivityintent.putextras(mybundelforname);openwelcomeactivityintent.setclass(androidbundel.this, welcome.class);startactivity(openwelcomeactivityintent);//从intent 中获取数据bundle mybundelforgetname=this.getintent().getextras();string name=mybundelforgetname.getstring("key_name");mytextview_showname.settext("欢迎您进入:"+name);private intent tonextintent;//intent 成员声明tonextintent=new intent();//intent 定义tonextintent.setclass(twoactivityme3.this, secondactivity3.class);//设定开启的下一个activitystartactivityforresult(tonextintent, request_ask);//开启intent 时候,把请求码同时传递-----------------------------------android 编程基础3在源请求activity 中等待intent 返回应答结果,通过重载onactivityresult()方法☻ 第一个参数是你开启请求intent时的对应请求码,可以自己定义。☻ 第二个参数是目标activity返回的验证结果码☻ 第三个参数是目标activity返回的intent目标activity 中发送请求结果代码,连同源activity 请求的数据一同绑定到bundle中通过intent 传回源请求activity 中log与ddms(查看log等信息)@overrideprotected void onactivityresult(int requestcode,int resultcode, intent data) {// todo auto-generated method stubsuper.onactivityresult(requestcode, resultcode, data);if(requestcode==request_ask){if(resultcode==result_canceled){settitle("cancel****");}else if(resultcode==result_ok){showbundle=data.getextras();//从返回的intent中获得bundlename=showbundle.getstring("myname");//从bundle中获得相应数据text.settext("the name get from the second layout:\n"+name);}}}backintent=new intent();stringbundle=new bundle();stringbundle.putstring("myname", name);backintent.putextras(stringbundle);setresult(result_ok, backintent);//返回activity结果码finish();


1、打开cmd输入netca。 2、选择【本地net服务名配置】→下一步。 3、选择【添加】→下一步。 4、在【服务名】中输入你想要连接的服务器上的oracle服务的名字→下一步。 5、选择【tcp】→下一步。 6、在【主机名】中输入你想要连接的服务器ip,端口号不变→下一步。 7、选择【进行测试】→下一步。(当然你也可以选择不测试) ※1测试如果不通过,点击【更改登录】输入一个肯定能登入的【用户名】和【口令】→确定,出现【正在连接...测试成功。】表明测试成功。 ※2测试不通过的话,点【上一步】确认你写的【服务名】和【主机名】,确认无误的情况下,确认你要连接的服务器oracle监听服务已经打开。 8、在【net服务名中】输入你想要使用的本地的服务名→下一步。 ※就是【sqlplus user/passwd @本地服务名】。 9、选择【否】→下一步。 10、出现【net服务配置完毕】字样→下一步。 11、点击【完成】完成服务配置。 12、在上面服务配置完成以后,在cmd中输入如下命令即可远程登录oracle服务器: sqlplus user_name/password@本地服务名 一定记住,上面的本地服务名是你第8步写的服务名。



3. jboss 的安全设置3.1 jmx-console 登录的用户名和密码设置 默认情况访问 http://localhost:8080/jmx-console 就可以浏览jboss的部署管理的一些信息,不需要输入用户名和密码,使用起来有点安全隐患。下面我们针对此问题对jboss进行配置,使得访问jmx-console也必须要知道用户名和密码才可进去访问。步骤如下:3.1.1 修改jboss-web.xml文件打开/server/default/deploy/jmx-console.war/web-inf/jboss-web.xml文件,去掉<security-domain>java:/jaas/jmx-console</security-domain>的注释。修改后的该文件内容为:<jboss-web>   <!-- uncomment the security-domain to enable security. you will      need to edit the htmladaptor login configuration to setup the      login modules used to authentication users.-->      <security-domain>java:/jaas/jmx-console</security-domain></jboss-web>3.1.2 修改web.xml文件与3.1.1中的jboss-web.xml同级目录下的web.xml文件,查找到<security-constraint/>节点,去掉它的注释,修改后该部分内容为:<!-- a security constraint that restricts access to the html jmx console   to users with the role jbossadmin. edit the roles to what you want and   uncomment the web-inf/jboss-web.xml/security-domain element to enable   secured access to the html jmx console.-->   <security-constraint>     <web-resource-collection>       <web-resource-name>htmladaptor</web-resource-name>       <description>an example security config that only allows users with the         role jbossadmin to access the html jmx console web application       </description>       <url-pattern>/*</url-pattern>       <http-method>get</http-method>       <http-method>post</http-method>     </web-resource-collection>     <auth-constraint>       <role-name>jbossadmin</role-name>     </auth-constraint>   </security-constraint>   在此处可以看出,为登录配置了角色jbossadmin。3.1.3 修改login-config.xml文件在第一步中的jmx-console安全域和第二步中的运行角色jbossadmin都是在login-config.xml中配置,我们在jboss安装目录/server/default/config下找到它。查找名字为:jmx-console的application-policy:<application-policy name = "jmx-console">       <authentication>          <login-module code="org.jboss.security.auth.spi.usersrolesloginmodule"             flag = "required">           <module-option name="usersproperties">props/jmx-console-users.properties</module-option>           <module-option name="rolesproperties">props/jmx-console-roles.properties</module-option>          </login-module>       </authentication>    </application-policy>在此处可以看出,登录的角色、用户等的信息分别在props目录下的jmx-console-roles.properties和jmx-console-users.properties文件中设置,分别打开这两个文件。其中jmx-console-users.properties文件的内容如下:# a sample users.properties file for use with the usersrolesloginmoduleadmin=admin该文件定义的格式为:用户名=密码,在该文件中,默认定义了一个用户名为admin,密码也为admin的用户,读者可将其改成所需的用户名和密码。jmx-console-roles.properties的内容如下:# a sample roles.properties file for use with the usersrolesloginmoduleadmin=jbossadmin, httpinvoker该文件定义的格式为:用户名=角色,多个角色以“,”隔开,该文件默认为admin用户定义了jbossadmin和httpinvoker这两个角色。配置完成后读者可以通过访问: http://localhost:8088/jmx-console/ ,输入jmx-console-roles.properties文件中定义的用户名和密码,访问jmx-console的页面。如图:


package action;import java.awt.image;import java.awt.toolkit;import java.awt.image.bufferedimage;import java.awt.image.cropimagefilter;import java.awt.image.filteredimagesource;import java.awt.image.imagefilter;import java.awt.image.imageproducer;import java.io.bufferedinputstream;import java.io.bufferedoutputstream;import java.io.file;import java.io.fileinputstream;import java.io.fileoutputstream;import java.io.ioexception;import java.io.inputstream;import java.io.outputstream;import java.util.arraylist;import java.util.date;import java.util.list;import java.util.map;import java.util.random;import javax.imageio.imageio;import javax.servlet.http.httpservletrequest;import org.apache.struts2.servletactioncontext;import po.blog;import po.login;import po.photo;import po.userinfo;import service.qqrservice;import util.imagehepler;import com.opensymphony.xwork2.actioncontext;import com.sun.image.codec.jpeg.jpegcodec;import com.sun.image.codec.jpeg.jpegimageencoder;public class kindeditoraction extends baseaction {	private static final long serialversionuid = 1l;	private qqrservice qqrservice;	// 封装参数	private file imgfile;	private string imgfilefilename;	private string imgfilecontenttype;	private string filedir = "/blogimg";	private string imgtitle = "";	private string align;	private int imgwidth = 0;	private int imgheight = 0;	// 上传kindeditor 图片及压缩	@suppresswarnings("deprecation")	public string uploadimg() throws exception {		// todo auto-generated method stub		// 只能传图片		try {			if (this.imgfile != null) {				file dir = new file(servletactioncontext.getrequest()						.getrealpath(filedir));				if (!dir.exists())					dir.mkdir();				integer login_id = (integer) actioncontext.getcontext()						.getsession().get("login_id");				date dt = new date();				file dst = new file(dir.getabsolutepath() + file.separator						+ login_id + new date().gettime() + ".jpg");				this.resize_image(this.imgfile, dst);				string id = "context";				string url = servletactioncontext.getrequest().getcontextpath()						+ "/" + this.filedir + "/" + dst.getname();				string border = "0";				string result = "<script type='text/javascript'>";				result += "parent.ke.plugin['image'].insert('" + id + "','"						+ url + "','" + imgtitle + "','" + imgheight + "','"						+ imgheight + "','" + border + "','" + align + "');   ";				result += "</script>";				servletactioncontext.getresponse().getwriter().write(result);			} else {				return null;			}		} catch (runtimeexception e) {			// todo auto-generated catch block			e.printstacktrace();		}		return null;	}	// 自己封装的一个把源文件对象复制成目标文件对象	public boolean copy(file src, file dst) {		inputstream in = null;		outputstream out = null;		try {			in = new bufferedinputstream(new fileinputstream(src), 1024);			out = new bufferedoutputstream(new fileoutputstream(dst), 1024);			byte[] buffer = new byte[1024];			int len = 0;			while ((len = in.read(buffer)) > 0) {				out.write(buffer, 0, len);			}			return true;		} catch (exception e) {			e.printstacktrace();			return false;		} finally {			if (null != in) {				try {					in.close();				} catch (ioexception e) {					e.printstacktrace();				}			}			if (null != out) {				try {					out.close();				} catch (ioexception e) {					e.printstacktrace();				}			}		}	}	/**	 * 图像压缩	 * 	 * @param fi大图文件	 * @param fo将要转换出的小图文件	 */	public boolean resize_image(file fi, file fo) {		try {			// file fi = new file("e:/3.jpg"); // 大图文件			// file fo = new file("e:/333.jpg"); // 将要转换出的小图文件			// affinetransform transform = new affinetransform();			bufferedimage bis = imageio.read(fi);			int w = bis.getwidth();			// system.out.println(w);			int h = bis.getheight();			// system.out.println(h);			// double scale = (double) w / h;			int nw = w;			int nh = h;			bufferedimage tag = new bufferedimage(nw, nh,					bufferedimage.type_int_rgb);			this.imgwidth = tag.getwidth();			this.imgheight = tag.getheight();			if (this.imgwidth > 250)				this.imgwidth = 250;			if (this.imgheight >= 250)				this.imgheight = 250;			tag.getgraphics().drawimage(bis, 0, 0, nw, nh, null); // 绘制缩小后的图			// 转换为32*32 jpg格式			fileoutputstream newimage = new fileoutputstream(fo); // 输出到文件流			jpegimageencoder encoder = jpegcodec.createjpegencoder(newimage);			encoder.encode(tag);			newimage.close();			return true;		} catch (exception e) {			e.printstacktrace();			return false;		}	}	public void imageshow(int width, int height, int w, int h) {		int i = width;		int j = height;		width = w;		height = h;		if (i > w) {			float width_bili = w / i;			float height_bili = h / j;			float bili = width_bili;			if (width_bili < height_bili) {				bili = width_bili;			} else {				bili = height_bili;			}			i = (int) (i * bili);			j = (int) (j * bili);		} else {			if (j > h) {				float bili = (float) (h / j);				i = (int) (i * bili);				j = (int) (j * bili);			}		}		width = i;		height = j;	}	/**	 * 图像的缩略	 * 	 * 	 * width 输出图片大小 height	 * 	 * @param fi大图文件	 * @param fo将要转换出的小图文件	 */	public boolean resize_image(file fi, file fo, int width, int height) {		try {			bufferedimage bis = imageio.read(fi);			int w = bis.getwidth();			int h = bis.getheight();			int nw = width;			int nh = height;			bufferedimage tag = new bufferedimage(nw, nh,					bufferedimage.type_int_rgb);			tag.getgraphics().drawimage(bis, 0, 0, nw, nh, null); // 绘制缩小后的图			// 转换为32*32 jpg格式			fileoutputstream newimage = new fileoutputstream(fo); // 输出到文件流			jpegimageencoder encoder = jpegcodec.createjpegencoder(newimage);			encoder.encode(tag);			newimage.close();			return true;		} catch (exception e) {			e.printstacktrace();			return false;		}	}	/**	 * 图像的等比缩略	 * 	 * 	 * width 输出图片大小 height	 * 	 * @param fi大图文件	 * @param fo将要转换出的小图文件	 */	public boolean geometric_image(file fi, file fo, int width, int height) {		try {			bufferedimage bis = imageio.read(fi);			int w = bis.getwidth();			int h = bis.getheight();			int nw = w;			int nh = h;			if (w > width) {				nw = width;				nh = nw * h / w;				if (nh > height) {					nh = height;					nw = nh * w / h;				}			} else if (h > height) {				nh = height;				nw = nh * w / h;				if (nw > width) {					nw = width;					nh = nw * h / w;				}			}			bufferedimage tag = new bufferedimage(nw, nh,					bufferedimage.type_int_rgb);			tag.getgraphics().drawimage(bis, 0, 0, nw, nh, null); // 绘制缩小后的图			// 转换为32*32 jpg格式			fileoutputstream newimage = new fileoutputstream(fo); // 输出到文件流			jpegimageencoder encoder = jpegcodec.createjpegencoder(newimage);			encoder.encode(tag);			newimage.close();			return true;		} catch (exception e) {			e.printstacktrace();			return false;		}	}	public string getimgtitle() {		return imgtitle;	}	public void setimgtitle(string imgtitle) {		this.imgtitle = imgtitle;	}	public string getalign() {		return align;	}	public void setalign(string align) {		this.align = align;	}	public qqrservice getqqrservice() {		return qqrservice;	}	public void setqqrservice(qqrservice qqrservice) {		this.qqrservice = qqrservice;	}	public file getimgfile() {		return imgfile;	}	public void setimgfile(file imgfile) {		this.imgfile = imgfile;	}	public string getimgfilefilename() {		return imgfilefilename;	}	public void setimgfilefilename(string imgfilefilename) {		this.imgfilefilename = imgfilefilename;	}	public string getimgfilecontenttype() {		return imgfilecontenttype;	}	public void setimgfilecontenttype(string imgfilecontenttype) {		this.imgfilecontenttype = imgfilecontenttype;	}	public string getfiledir() {		return filedir;	}	public void setfiledir(string filedir) {		this.filedir = filedir;	}}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值