`
superyang
  • 浏览: 22161 次
  • 性别: Icon_minigender_2
  • 来自: 广州
社区版块
存档分类
最新评论

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  

//数据写入Intent
Intent 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 {
@Override
public 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(){
@Override
public 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(){
@Override
public void onClick(View v) {
Intent openWelcomeActivityIntent=new Intent();
openWelcomeActivityIntent.setClass(AndroidStudy_TWO.this,
Welcome.class);
startActivity(openWelcomeActivityIntent);
}
});
button_showLoginName.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
result.setText(inName.getText()+"欢迎您进入");
}
});
}
}





使用Bundle在Activity间传递数据2
从源请求Activity 中通过一个Intent 把一个服务请求传到目标Activity 中
//数据写入Intent
Intent 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);
//设定开启的下一个Activity
startActivityForResult(toNextIntent, REQUEST_ASK);
//开启Intent 时候,把请求码同时传递
-----------------------------------Android 编程基础
3
在源请求Activity 中等待Intent 返回应答结果,通过重载onActivityResult()方法
☻ 第一个参数是你开启请求Intent时的对应请求码,可以自己定义。
☻ 第二个参数是目标Activity返回的验证结果码
☻ 第三个参数是目标Activity返回的Intent
目标Activity 中发送请求结果代码,连同源Activity 请求的数据一同绑定到Bundle
中通过Intent 传回源请求Activity 中
Log与DDMS(查看Log等信息)
@Override
protected void onActivityResult(int requestCode,
int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if(requestCode==REQUEST_ASK){
if(resultCode==RESULT_CANCELED){
setTitle("Cancel****");
}else if(resultCode==RESULT_OK){
showBundle=data.getExtras();//从返回的Intent中获得Bundle
Name=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 UsersRolesLoginModule
admin=admin
该文件定义的格式为:用户名=密码,在该文件中,默认定义了一个用户名为admin,密码也为admin的用户,读者可将其改成所需的用户名和密码。
jmx-console-roles.properties的内容如下:
# A sample roles.properties file for use with the UsersRolesLoginModule
admin=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;
	}

}
分享到:
评论
1 楼 lerylee800 2011-01-13  
咋木有格式化一下呢

相关推荐

    Android Intent和Intent Filter详解

     三种应用程序基本组件——activity, service和broadcast receiver——是使用称为intent的消息来激活的。Intent消息传递是一种组件间运行时绑定的机制. intent是Intent对象, 它包含了需要做的操作的描述, 或者, ...

    《Android应用开发详解》源码_文档讲解

    《Android应用开发详解源码》目录第1章 Android概述 第2章 Android开发基础 第3章 Android中的资源访问 第4章 Android用户界面 第5章 Android基本程序单元Activity 第6章 Android组件之间的信使Intent 第7章 Android...

    Android开发指南中文版-----应用程序框架

    意图和意图过滤器Intents and Intent Filters 43 意图过滤器Intent filters 47 通常情况Common cases 51 使用意图匹配Using intent matching 52 数据存储Data Storage 52 概览Storage quickview 52 ? 系统偏好:快速...

    新版Android开发教程.rar

    The sections below describe the system and software requirements for developing Android applications using the Android SDK tools included in Android 1.1 SDK, Release 1. Supported Supported Supported ...

    android的activity跳转到另一个activity

    当然,据网上有人将要比较安全的实现关闭程序的功能也不是挺简单的,因为android有专门的退出键返回键等。所以该Close按钮暂时没去实现它。我的第1个activity为HelloworldActivity,第2个activity为NextActivity.实验...

    Android开发宝典.rar

    意图和意图过滤器Intents and Intent Filters 43 意图过滤器Intent filters 47 通常情况Common cases 51 使用意图匹配Using intent matching 52 数据存储Data Storage 52 概览Storage quickview 52  系统...

    Android移动应用开发实验指导书.docx

    (2)Intent是Android程序中各组件之间进行交互的一种重要方式,它不仅可以指明当前组件想要执行的动作,还可以在不同组件之间传递数据。 任务 1、请在AndroidManifest.xml文件中配置SecondActivity: 配置Intent的...

    android中Activity详解(生命周期、以各种方式启动Activity、状态保存,完全退出等)

    在一个应用程序中通常由多个Activity构成,都会在Manifestxml中指定一个主的Activity,如下设置 &lt;actionandroid name=AndroidintentactionMAIN&gt; 当程序第一次运行时用户就会看这个Activity,这个Activity可以通过...

    android 退出程序解决内存释放的问题

    做Android项目的时候发现一个问题:当应用程序退出了,点击”设置”查看应用程序,界面显示着可以点击”强制关闭”. 我认为造成这样的原因是还有开启的activity没有被destroy,然后做调试,之后发现开启的activity应该是...

    Android移动应用开发实验指导书.docx.docx

    (2)Intent是Android程序中各组件之间进行交互的一种重要方式,它不仅可以指明当前组件想要执行的动作,还可以在不同组件之间传递数据。 任务 1、请在AndroidManifest.xml文件中配置SecondActivity: 配置Intent的...

    andbook中文版

    13 Android Code Challenge……………… 14 创建Android 应用程序…………………15 剖析一个Android 应用程序……………………… 15 Activity…………………………………………………………………15 Intent ...

    Android 代码分析

    14 Input Event Detect and Dispatch 47 15 Input Event Processing 48 16 Manually create system.img in Android 50 17 Manually update settings in command line 51 18 Only re-build a specific folder in ...

    Android开发指南中文版

    意图和意图过滤器Intents and Intent Filters 43 意图过滤器Intent filters 47 通常情况Common cases 51 使用意图匹配Using intent matching 52 数据存储Data Storage 52 概览Storage quickview 52  系统偏好:...

    android群雄传

    9.3 Android Apk应用信息获取之Activity Manager 215 9.4 解析Packages.xml获取系统信息 218 9.5 Android安全机制 220 9.5.1 Android安全机制简介 220 9.5.2 Android系统安全隐患 222 9.5.3 Android Apk反编译 ...

    android 使用浏览器打开指定页面的实现方法

    在Android程序中我们可以通过发送隐式Intent来启动系统默认的浏览器。如果手机本身安装了多个浏览器而又没有设置默认浏览器的话,系统将让用户选择使用哪个浏览器来打开连接。 Uri uri = Uri.parse...

    【android编程】第八讲-Intent和BroadcastReceiver

    本讲介绍了Android应用程序中最为重要Intent和四大组件之一 文章目录第八讲Intent和BroadcastReceiverIntentIntent对象构成Component nameActionDataCategoryExtrasFlagsURI和intent-filter匹配:一个打电话和发短信...

    Android手机天气预报项目报告(2).docx

    Android的开发组Activity、Intent Receiver、Service、Content Provider等,可以实现不同页面之间的跳转;数据的获取和实现与数据库的实时交互;不同页面和进程间数据的共享. 2.3 数据库设计 本软件中有两部分数据...

    android实现静默安装与卸载的方法

    方法1:【使用调用接口方法,由于安装卸载应用程序的部分API是隐藏的,所以必须下载Android系统源码,在源码下开发并编译之后使用MM命令编译生成APK文件】 import java.io.File; import android.app.Activity; ...

Global site tag (gtag.js) - Google Analytics