学习提示:在学习开发前你需要获得微软开发中帐号可以查看本篇文档,《wp7(windows phone 7 )开发者帐号注册,dreamspark注册,edu.cn节约99刀》(http://kwor.blog.163.com/blog/static/1296224112011616503319/)
1.安装vs2010 for wp7,直接到dreamspark下载免费版的,可参考《dreamspark 注册,wp7 app hub微软手机开发者帐号(全新3步注册)》本篇教程(http://kwor.blog.163.com/blog/static/129622411201152882016637/)下面是下载地址(https://www.dreamspark.com/Products/Product.aspx?ProductId=28)
2.新建项目:选择
3.这里有6种类型的类型的项目:
一、windows phone application 普通项目
二、windows phone Databound Application 带数据绑定类型的
三、windows phone class library 类库
四、windows phone panorama Application 全屏项目类型(里面是Panorama控件)
五、windows phone pivot Application 枢纽类型(里面是pivot 控件)
下级我们详细谈谈几个项目的创建和结构。
1. 现状与目的
1、门户网站(ROOT目录)下面有很多小应用,由于历史遗留原因,上面有很多小应用,这些小应用都没有使用连接池(因为不可以在一个应用里部署多个连接池,hibernate版本太老造成的),通过使用容器提供的连接池,把ROOT下的小应用程序都改为使用连接池的,可以提高应用性能。
2、Dbcp连接池有个bug(主要是应用中使用的hibernate的版本太老了,hibernate启用不了dbcp自动关闭连接的特性),如果应用维护连接池,removeAbandoned(检查没有关闭的连接,自动关闭)不生效,通过使用容器提供的连接池,可以自动关闭idle连接。通过使用logAbandoned,dbcp打印没有关闭连接应用的堆栈信息,可以方便找出没有正确关闭连接的应用,便于应用bug检查。
2. 配置修改与使用
1、 修改tomcat6配置:
l 加入oracle驱动
把ojdbc14.jar复制到%CATALINA_HOME%/lib目录
l 加入tomcat连接池配置
修改%CATALINA_HOME%/conf/context.xml,增加下列配置
<Resource
name="jdbc/cqydt"
auth="Container"
type="javax.sql.DataSource"
driverClassName="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:thin:@10.191.34.117:1521:ecom"
username="cqydt"
password="cqydt-117-passwd123"
maxActive="20"
maxIdle="5"
removeAbandoned="true"
removeAbandonedTimeout="60"
logAbandoned="true"
maxWait="3000"/>
<Resource
name="jdbc/cqydwsc"
auth="Container"
type="javax.sql.DataSource"
driverClassName="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:thin:@10.191.34.117:1521:ecom"
username="cqydwsc1"
password="cqydwsc-117-passwd123"
maxActive="40"
maxIdle="5"
removeAbandoned="true"
removeAbandonedTimeout="60"
logAbandoned="true"
maxWait="3000"/>
<Resource
name="jdbc/cqmcuser"
auth="Container"
type="javax.sql.DataSource"
driverClassName="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:thin:@10.191.34.117:1521:ecom"
username="cqmcuser "
password="cqmcuser-117-passwd123"
maxActive="20"
maxIdle="5"
removeAbandoned="true"
removeAbandonedTimeout="60"
logAbandoned="true"
maxWait="3000"/>
上面配置cqydwc1、cqydt、cqmcuser用户的连接池。
2、 修改小应用,获取数据库连接
获取cqydt的连接
Context initCtx = new InitialContext();
ds = (DataSource) initCtx.lookup("java:comp/env/jdbc/cqydt");
Connection conn = ds.getConnection();
获取cqmcuser的连接
Context initCtx = new InitialContext();
ds = (DataSource) initCtx.lookup("java:comp/env/jdbc/cqmcuser");
Connection conn = ds.getConnection();
获取cqydwsc的连接
Context initCtx = new InitialContext();
ds = (DataSource) initCtx.lookup("java:comp/env/jdbc/cqydt");
Connection conn = ds.getConnection();
3、 修改应用配置
删除原有hibernate中关于数据的配置,保留
<property name="dialect">
net.sf.hibernate.dialect.OracleDialect
</property>
增加
<property name="hibernate.connection.datasource">java:/comp/env/jdbc/cqydwsc</property>
<property name="hibernate.connection.datasource">java:/comp/env/jdbc/cqydt </property>
<property name="hibernate.connection.datasource">java:/comp/env/jdbc/cqmcuser</property>
3. 测试
以上配置在以下环境配置生效:
os:win 7 (64 bit)
jvm: jrockit 6.x (64 bit)
tomcat: 6.0.x(64 bit)
jdbc driver:ojdbc14.jar
hibernate:2.0
jsp:2.5
需测试在服务器环境中测试能否生效,测试内容包括:
1. 应用是否能正常使用
2. 测试连接池是否能自动关闭超过removeAbandonedTimeout时间后的连接,检查是否能定位到没有关闭连接的应用,在测试时,removeAbandonedTimeout值配置为300(5分钟)。
测试连接池配置如下:
<Resource
name="jdbc/cqmcuser"
auth="Container"
type="javax.sql.DataSource"
driverClassName="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:thin:@10.191.34.117:ecom"
username="cqmcuser "
password="cqmcuser-117-passwd123"
maxActive="20"
maxIdle="5"
removeAbandoned="true"
removeAbandonedTimeout="300"
logAbandoned="true"
maxWait="3000"/>
测试脚本如下:
<!doctype html public "-//w3c//dtd html 4.0 transitional//en" "http://www.w3.org/TR/REC-html40/strict.dtd">
<%@ page import="java.sql.*"%>
<%@ page import="javax.sql.*"%>
<%@ page import="javax.naming.*"%>
<%@ page import="org.apache.commons.logging.Log"%>
<%@ page import="org.apache.commons.logging.LogFactory"%>
<%@ page session="false"%>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<%
Log log = LogFactory.getLog(this.getClass());
DataSource ds = null;
try {
Context initCtx = new InitialContext();
ds = (DataSource) initCtx.lookup("java:comp/env/jdbc/cqmcuser");
Connection conn = ds.getConnection();
log.info("get connect success");
Statement stmt = conn.createStatement();
String strSql = " select 'yes' from dual";
ResultSet rs = stmt.executeQuery(strSql);
while (rs.next()) {
out.println("<br/>");
out.print(rs.getString(1));
out.println("<br/>");
out.println("Test Success");
out.println("<br/>");
}
log.info("execute sql success");
} catch (Exception ex) {
out.print(ex.getMessage());
log.info(ex.getStackTrace());
}
%>
此脚本没有关闭数据库连接。执行此脚本,直到出现Cannot get a connection, pool exhausted,此时连接池已经耗尽,然后等待300秒后继续测试,查看是否可以成功连接,测试是否能够通过日志找到此脚本。
之前听说gallery做图片浏览很不错。最近也听到一朋友要做这个,听他说要改gallery源码,我想应该不用那么复杂吧。
游览图片就是点击图片放大,看代码吧。
package com.hua.com; import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.view.View; import android.view.ViewGroup; import android.view.animation.Animation; import android.view.animation.AnimationSet; import android.view.animation.ScaleAnimation; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.AdapterView.OnItemSelectedListener; import android.widget.BaseAdapter; import android.widget.Gallery; import android.widget.ImageView; public class TestGalleryActivity extends Activity { private Gallery gallery; private AnimationSet manimationSet; private int[] imgs; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); init(); } private void init(){ imgs=new int[]{R.drawable.a,R.drawable.c,R.drawable.d,R.drawable.y,R.drawable.f}; gallery = (Gallery)findViewById(R.id.gy_main); ImageAdapter imgAdapter = new ImageAdapter(this,imgs); gallery.setAdapter(imgAdapter); gallery.setSelection(imgs.length/2); gallery.setOnItemClickListener(listener); } private OnItemClickListener listener = new OnItemClickListener(){ @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if(position!=0&&position!=4){ AnimationSet animationSet = new AnimationSet(true); if(manimationSet!=null&&manimationSet!=animationSet){ ScaleAnimation scaleAnimation = new ScaleAnimation(2,0.5f,2,0.5f, Animation.RELATIVE_TO_SELF,0.5f, //使用动画播放图片 Animation.RELATIVE_TO_SELF,0.5f); scaleAnimation.setDuration(1000); manimationSet.addAnimation(scaleAnimation); manimationSet.setFillAfter(true); //让其保持动画结束时的状态。 view.startAnimation(manimationSet); } ScaleAnimation scaleAnimation = new ScaleAnimation(1,2f,1,2f, Animation.RELATIVE_TO_SELF,0.5f, Animation.RELATIVE_TO_SELF,0.5f); scaleAnimation.setDuration(1000); animationSet.addAnimation(scaleAnimation); animationSet.setFillAfter(true); view.startAnimation(animationSet); manimationSet = animationSet; }else{ if(null!=manimationSet)manimationSet.setFillAfter(false); } } }; class ImageAdapter extends BaseAdapter{ private Context ct; private int[] data; public ImageAdapter(Context ct,int[] data){ this.ct=ct; this.data=data; } @Override public int getCount() { return data.length; } @Override public Object getItem(int position) { return data[position]; } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { View view = null; if(convertView==null){ ImageView img = new ImageView(ct); img.setImageResource(data[position]); view=img; }else{ view=convertView; } return view; } } }
布局文件
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <Gallery android:id="@+id/gy_main" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_gravity="center_horizontal" android:spacing="10dip" android:layout_centerHorizontal="true" /> </LinearLayout>
这样的话,图片位置是0 或者4 时候,点击就没有反应了,
尝试修改了一下
!(position<0) && position!=4
结果,点击第一张可以放大了,但是点击空白的位置,图片不会回复原来状态了。
可以帮忙说下原因不。
flyingsir.zw@gmail.com 谢谢。
int i = 10; private OnItemClickListener listener = new OnItemClickListener(){ @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if(position!=i){ i = position; manimationSet.setFillAfter(false); } ScaleAnimation scaleAnimation = new ScaleAnimation(1,2f,1,2f, Animation.RELATIVE_TO_SELF,0.5f, Animation.RELATIVE_TO_SELF,0.5f); scaleAnimation.setDuration(1000); animationSet.addAnimation(scaleAnimation); animationSet.setFillAfter(true); view.startAnimation(animationSet); manimationSet = animationSet; }else{ if(null!=manimationSet)manimationSet.setFillAfter(false); } } };